Thread: Pointer walk

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    903

    Pointer walk

    This is how you increment a pointer to read the string from a certain point.

    Now how should i go to do the same with an array like response[255] ?

    Should i use
    Code:
    pos = str.find("live");        // position of "live" in str
    str3 = str.substr (pos);   // get from "live" to the end
    or is there anything better?

    Code:
    int main()
    {
        char * response = "c:\\hello world";
        for(int i=0;i<3;i++) *response++;
        printf("%s\n", response);
    
        return 0;
    }
    Last edited by Ducky; 04-04-2010 at 08:17 AM.
    Windows 10 with Visual Studio 14.0.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    Quote Originally Posted by Ducky View Post
    Should i use
    Code:
    pos = str.find("live");        // position of "live" in str
    str3 = str.substr (pos);   // get from "live" to the end
    or is there anything better?
    there are no such things in C. It is C++

    So start with deciding which language you want to use.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    903
    Yeah well, sorry, maybe i should have asked: how to do this in C? Thanks.
    Windows 10 with Visual Studio 14.0.

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    look at the strstr function
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    903
    Thanks Vart!

    Code:
        char str[] ="This is a simple string";
        char * pch;
        pch = strstr (str,"simple");
        printf("%s",pch);
    Windows 10 with Visual Studio 14.0.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick Pointer Question
    By gwarf420 in forum C Programming
    Replies: 15
    Last Post: 06-01-2008, 03:47 PM
  2. Parameter passing with pointer to pointer
    By notsure in forum C++ Programming
    Replies: 15
    Last Post: 08-12-2006, 07:12 AM
  3. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  4. How did you master pointers?
    By Afrinux in forum C Programming
    Replies: 15
    Last Post: 01-17-2006, 08:23 PM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM