C++ probs...

Status
Not open for further replies.

legolas

Padawan
hi,

i am working in FC4, gcc3.2 compiler. pls help me doing this.

i have a string say,

string str1 = "/home/legolas/contents/EP1"

now i hav to find the location of the last occurance of "/" character from this string (22 in this case with index 0) and then i hav to get teh string upto that...

that is, /home/legolas/contents/

how do i do this?

/legolas
 

ujjwal

Padawan
i=strlen(str1);
while(i)
{
if(str1[--i]=='\\') // Escape character for \
return i;
}

This will give you the value of i (by traversing the string from end to start, and returning the position of the first / it meets).

Now you can copy the string uptill this position.
 

vignesh

Wise Old Owl
One question on bash ujjwal... read accepts input from the std input ok and -s stops the echoing.. (i.e) the entered text is not displayed on the screen .. Now I have a menu and get a number as the option How to make it go to the req pos in the if/case without pressing return ?

So when I press a number the corresponding code is executed without typing the number and pressing the enter key.
 
Status
Not open for further replies.
Top Bottom