home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / lib / dlibssrc / strtok.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-06-14  |  1.2 KB  |  38 lines

  1. #include <d:\usr\stdlib\stdio.h>
  2.  
  3. static    char    *_strtok = NULL;    /* local token pointer */
  4.  
  5. char *strtok(string, delim)
  6. register char *string;
  7. register char *delim;
  8. /*
  9.  *    Return a token from <string>.  If <string> in not NULL, it is
  10.  *    the beginning of a string from which tokens are to be extracted.
  11.  *    Characters found in <delim> are skipped over to find the start
  12.  *    of a token, characters are then accumulated until a character in
  13.  *    <delim> is found, or the terminator of <string> is reached.
  14.  *    A pointer to the '\0' terminated token is then returned.  Note
  15.  *    that this function modifies <string> (by inserting '\0's) in
  16.  *    the process.  Subsequent calls to strtok() may specify NULL as
  17.  *    the <string> argument, in which case subsequent tokens are
  18.  *    returned, or NULL if there are no more tokens.
  19.  */
  20. {
  21.     register char *p;
  22.     char *strchr();
  23.  
  24.     if(string == NULL)
  25.         string = _strtok;
  26.     while(*string && strchr(delim, *string))
  27.         ++string;
  28.     if(*string == '\0')        /* no more tokens */
  29.         return(NULL);
  30.     p = string;
  31.     while(*string && !strchr(delim, *string))
  32.         ++string;
  33.     if(*string != '\0')
  34.         *string++ = '\0';
  35.     _strtok = string;
  36.     return(p);
  37. }
  38.