Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <string.h>
    char *strtok( char *s1, const char *s2 );
    char __far *_fstrtok( char __far *s1,
                          const char __far *s2 );
    #include <wchar.h>
    wchar_t *wcstok( wchar_t *s1, const wchar_t *s2,
                     wchar_t **ptr );
    #include <mbstring.h>
    unsigned char *_mbstok( unsigned char *s1,
                      const unsigned char *s2 );
    unsigned char __far *_fmbstok( unsigned char __far *s1,
                             const unsigned char __far *s2 );

Description:
    The strtok function is used to break the string pointed to by s1 into a
    sequence of tokens, each of which is delimited by a character from the
    string pointed to by s2.  The first call to strtok will return a pointer
    to the first token in the string pointed to by s1.  Subsequent calls to
    strtok must pass a NULL pointer as the first argument, in order to get
    the next token in the string.  The set of delimiters used in each of
    these calls to strtok can be different from one call to the next.

    The first call in the sequence searches s1 for the first character that
    is not contained in the current delimiter string s2.  If no such
    character is found, then there are no tokens in s1 and the strtok
    function returns a NULL pointer.  If such a character is found, it is
    the start of the first token.

    The strtok function then searches from there for a character that is
    contained in the current delimiter string.  If no such character is
    found, the current token extends to the end of the string pointed to by
    s1.  If such a character is found, it is overwritten by a null
    character, which terminates the current token.  The strtok function
    saves a pointer to the following character, from which the next search
    for a token will start when the first argument is a NULL pointer.

    Because strtok may modify the original string, that string should be
    duplicated if the string is to be re-used.

    The _fstrtok function is a data model independent form of the strtok
    function.  It accepts far pointer arguments and returns a far pointer.
     It is most useful in mixed memory model applications.

    The wcstok function is a wide-character version of strtok that operates
    with wide-character strings.  The third argument ptr points to a
    called-provided  wchar_t pointer into which the wcstok function stores
    information necessary for it to continue scanning the same wide string.

    On the first call in the sequence of calls to wcstok, s1 points to a
    wide string.  In subsequent calls for the same string, s1 must be NULL.
    If s1 is NULL, the value pointer to by ptr matches that set by the
    previous call to wcstok for the same wide string.  Otherwise, the value
    of ptr is ignored.  The list of delimiters pointed to by s2 may be
    different from one call to the next.  The tokenization of s1 is similar
    to that for the strtok function.

    The _mbstok function is a multibyte character version of strtok that
    operates with multibyte character strings.

    The _fmbstok function is a data model independent form of the _mbstok
    function that accepts far pointer arguments.  It is most useful in mixed
    memory model applications.

Returns:
    The strtok function returns a pointer to the first character of a token
    or NULL if there is no token found.

Example:
    #include <stdio.h>
    #include <string.h>

    void main()
      {
        char *p;
        char *buffer;
        char *delims = { " .," };

        buffer = strdup( "Find words, all of them." );
        printf( "%s\n", buffer );
        p = strtok( buffer, delims );
        while( p != NULL ) {
          printf( "word: %s\n", p );
          p = strtok( NULL, delims );
        }
        printf( "%s\n", buffer );
      }

    produces the following:

    Find words, all of them.
    word: Find
    word: words
    word: all
    word: of
    word: them
    Find

Classification:
    strtok is ANSI, _fstrtok is not ANSI, wcstok is ANSI, _mbstok is not
    ANSI, _fmbstok is not ANSI

Systems:
     strtok - All, Netware

    _fstrtok - All
    wcstok - All
    _mbstok - DOS, Windows, Win386, Win32, OS/2 1.x(all), OS/2-32
    _fmbstok - DOS, Windows, Win386, Win32, OS/2 1.x(all), OS/2-32

See Also:
    strcspn, strpbrk

See Also:

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson