CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2002
    Posts
    18

    Question Is there a function like strtok() that can use "TD" as delimiter characters?

    I used
    char *strtok(
    char *strToken,
    const char *strDelimit
    );
    in my program, and set strDelimit="TD". But I found whenever it met 'T' or 'D' it will take it as the delimiter. But I want the delimiter is "TD"(two characters together), not 'T' or 'D' alone.

    Which function should I use?

  2. #2
    Join Date
    Jun 2002
    Location
    Letchworth, UK
    Posts
    1,020
    Try strstr. It will tell you where the TD is. You will have to start the next search after the TD. Unlike strtok, it is thread safe and doesn't modify the string in any way.
    Succinct is verbose for terse

  3. #3
    Join Date
    Jul 2002
    Location
    Connecticut, U.S.
    Posts
    275
    Unlike strtok, it is thread safe and doesn't modify the string in any way.
    Are you refering to Visual C++? According to MSDN, it is "thread safe".

    from MSDN:
    Note Each function uses a static variable for parsing the string into tokens. If multiple or simultaneous calls are made to the same function, a high potential for data corruption and inaccurate results exists. Therefore, do not attempt to call the same function simultaneously for different strings and be aware of calling one of these functions from within a loop where another routine may be called that uses the same function. However, calling this function simultaneously from multiple threads does not have undesirable effects.
    Regards,
    John Flegert

  4. #4
    Join Date
    Jun 2002
    Location
    Letchworth, UK
    Posts
    1,020
    Are you refering to Visual C++? According to MSDN, it is "thread safe".
    Actually, I was referring to Unix: Solaris in particular. On Solaris, strtok_r is the thread safe version. I don't know how thread safe it is on the other flavours of Unix.
    Succinct is verbose for terse

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