Pointer walk

This is a discussion on Pointer walk within the C Programming forums, part of the General Programming Boards category; This is how you increment a pointer to read the string from a certain point. Now how should i go ...

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

    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.
    Compiler MSVC++ 2013 with Code::Blocks.

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    796
    Yeah well, sorry, maybe i should have asked: how to do this in C? Thanks.
    Compiler MSVC++ 2013 with Code::Blocks.

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    look at the strstr function
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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

    Code:
        char str[] ="This is a simple string";
        char * pch;
        pch = strstr (str,"simple");
        printf("%s",pch);
    Compiler MSVC++ 2013 with Code::Blocks.

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, 07:23 PM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21