home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / SNIP9404.ZIP / STPTOK.C < prev    next >
C/C++ Source or Header  |  1994-04-03  |  1KB  |  39 lines

  1. /*
  2. **  stptok() -- public domain by Ray Gardner, modified by Bob Stout
  3. **
  4. **   You pass this function a string to parse, a buffer to receive the
  5. **   "token" that gets scanned, the length of the buffer, and a string of
  6. **   "break" characters that stop the scan.  It will copy the string into
  7. **   the buffer up to any of the break characters, or until the buffer is
  8. **   full, and will always leave the buffer null-terminated.  It will
  9. **   return a pointer to the first non-breaking character after the one
  10. **   that stopped the scan.
  11. */
  12.  
  13. #include <string.h>
  14. #include <stdlib.h>
  15.  
  16. char *stptok(const char *s, char *tok, size_t toklen, char *brk)
  17. {
  18.       char *lim, *b;
  19.  
  20.       if (!*s)
  21.             return NULL;
  22.  
  23.       lim = tok + toklen - 1;
  24.       while ( *s && tok < lim )
  25.       {
  26.             for ( b = brk; *b; b++ )
  27.             {
  28.                   if ( *s == *b )
  29.                   {
  30.                         *tok = 0;
  31.                         return (char *)s;
  32.                   }
  33.             }
  34.             *tok++ = *s++;
  35.       }
  36.       *tok = 0;
  37.       return (char *)s;
  38. }
  39.