home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / compiler / clib / strtok.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-09  |  1.5 KB  |  90 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: strtok.c,v 1.1 1996/12/11 11:18:29 aros Exp $
  4.  
  5.     Desc: ANSI C function strtok()
  6.     Lang: english
  7. */
  8. #include <stdio.h>
  9.  
  10. /*****************************************************************************
  11.  
  12.     NAME */
  13. #include <string.h>
  14.  
  15.     char * strtok (
  16.  
  17. /*  SYNOPSIS */
  18.     char       * str,
  19.     const char * sep)
  20.  
  21. /*  FUNCTION
  22.     Separates a string by the characters in sep.
  23.  
  24.     INPUTS
  25.     str - The string to check or NULL if the next word in
  26.         the last string is to be searched.
  27.     sep - Characters which separate "words" in str.
  28.  
  29.     RESULT
  30.     The first word in str or the next one if str is NULL.
  31.  
  32.     NOTES
  33.     The function changes str !
  34.  
  35.     EXAMPLE
  36.     char buffer[64];
  37.  
  38.     strcpy (buffer, "Hello, this is a test.");
  39.  
  40.     // Init. Returns "Hello"
  41.     strtok (str, " \t,.");
  42.  
  43.     // Next word. Returns "this"
  44.     strtok (NULL, " \t,.");
  45.  
  46.     // Next word. Returns "is"
  47.     strtok (NULL, " \t");
  48.  
  49.     // Next word. Returns "a"
  50.     strtok (NULL, " \t");
  51.  
  52.     // Next word. Returns "test."
  53.     strtok (NULL, " \t");
  54.  
  55.     // Next word. Returns NULL.
  56.     strtok (NULL, " \t");
  57.  
  58.     BUGS
  59.  
  60.     SEE ALSO
  61.  
  62.     INTERNALS
  63.  
  64.     HISTORY
  65.     11.12.1996 digulla created. Original code by libnix.
  66.  
  67. ******************************************************************************/
  68. {
  69.     static char * t;
  70.  
  71.     if (str != NULL)
  72.     t = str;
  73.     else
  74.     str = t;
  75.  
  76.     str += strspn (str, sep);
  77.  
  78.     if (*str == '\0')
  79.     return NULL;
  80.  
  81.     t = str;
  82.  
  83.     t += strcspn (str, sep);
  84.  
  85.     if (*t != '\0')
  86.     *t ++ = '\0';
  87.  
  88.     return str;
  89. } /* strtok */
  90.