strtok.c 612 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /* $Id$ */
  6. #include <string.h>
  7. char *
  8. strtok(register char *string, const char *separators)
  9. {
  10. register char *s1, *s2;
  11. static char *savestring;
  12. if (string == NULL) {
  13. string = savestring;
  14. if (string == NULL) return (char *)NULL;
  15. }
  16. s1 = string + strspn(string, separators);
  17. if (*s1 == '\0') {
  18. savestring = NULL;
  19. return (char *)NULL;
  20. }
  21. s2 = strpbrk(s1, separators);
  22. if (s2 != NULL)
  23. *s2++ = '\0';
  24. savestring = s2;
  25. return s1;
  26. }