CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2006
    Location
    beyond the pillars of hercules
    Posts
    295

    [RESOLVED] finding the offset in a char array

    i have an array of char that looks like this:

    "This_is_my_example_string"

    im splitting the string on every "_" character , but also i want to find the position After the last "_" character and store it on an integer variable

    how can i do that?

    Code:
       Splits = strtok( cBuffer, "_" );
       while( Splits != NULL )
       {
              Splits = strtok( NULL, "_" );
    
       }

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: finding the offset in a char array

    If the return value of strtok() is not NULL, then subtract the return value of strtok from the address of the buffer you're searching.

    Edit:

    Sorry, that should be subtract the starting address of the buffer from the return value of strtok.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; March 22nd, 2009 at 01:11 PM. Reason: Clarification:

  3. #3
    Join Date
    May 2006
    Location
    beyond the pillars of hercules
    Posts
    295

    Re: finding the offset in a char array

    thanks for the idea

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: finding the offset in a char array

    Quote Originally Posted by Cpp_Noob View Post
    thanks for the idea
    Before doing anything, see the edit to my post.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured