[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

sub string

Posted on 2005-05-17
5
Medium Priority
?
400 Views
Last Modified: 2012-05-05
How can I create a sub string from a char buffer based on the last position of a charcter in the string?
for Example I have a char buffer :

char curdir[ 255]; which is "C:\Program Files\My App\new\ blah"

I want to return a string from the last index of "\".
which would leave a substring of " C:\Program Files\My App\new"

Spunog
0
Comment
Question by:spunog
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 14017608
char * lastBackSlash = strrchr ( curdir, "\\" );

if ( lastBackSlash != NULL )
{
 ...
}

//Paul
0
 

Author Comment

by:spunog
ID: 14017886
Thanks,

I'm a total novice with this stuff. What would the lines be to create the substring ?

SPunog
0
 
LVL 16

Accepted Solution

by:
PaulCaswell earned 200 total points
ID: 14017974
Once you've found the '\' character, replace it with a string termination character '\0' and the original 'curdir' string will now read 'C:\Program Files\My App\new' as you wish.

Just in case this is homework (and I am not sure that it is) I will try to avoid actually doing the work for you as this is against EE rules.

Paul
0
 

Author Comment

by:spunog
ID: 14018275
I don't normally work with C and I'm just stuck for time right now. If  you could spell it out I would apreciate it.

Cheers
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 14018368
>>Once you've found the '\' character, replace it with a string termination character '\0' and the original 'curdir' string will now read 'C:\Program Files\My App\new' as you wish.
This does - sort-of - spell it out.

Paul
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question