C++ probs...

Discussion in 'Open Source' started by legolas, May 1, 2006.

Thread Status:
Not open for further replies.
  1. legolas

    legolas New Member

    Joined:
    Feb 8, 2005
    Messages:
    959
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. ujjwal

    ujjwal New Member

    Joined:
    Dec 1, 2003
    Messages:
    780
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  3. vignesh

    vignesh New Member

    Joined:
    Jul 20, 2004
    Messages:
    1,658
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Chennai
    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.
     
Thread Status:
Not open for further replies.

Share This Page