Fixes to comments.
[AROS.git] / compiler / clib / strtok.c
blob1af63c4c23083a4f790bfb258e7ebbdae21456c6
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C function strtok().
6 */
8 /*****************************************************************************
10 NAME */
11 #include <string.h>
13 char * strtok (
15 /* SYNOPSIS */
16 char * str,
17 const char * sep)
19 /* FUNCTION
20 Separates a string by the characters in sep.
22 INPUTS
23 str - The string to check or NULL if the next word in
24 the last string is to be searched.
25 sep - Characters which separate "words" in str.
27 RESULT
28 The first word in str or the next one if str is NULL.
30 NOTES
31 The function changes str !
33 EXAMPLE
34 char buffer[64];
36 strcpy (buffer, "Hello, this is a test.");
38 // Init. Returns "Hello"
39 strtok (str, " \t,.");
41 // Next word. Returns "this"
42 strtok (NULL, " \t,.");
44 // Next word. Returns "is"
45 strtok (NULL, " \t");
47 // Next word. Returns "a"
48 strtok (NULL, " \t");
50 // Next word. Returns "test."
51 strtok (NULL, " \t");
53 // Next word. Returns NULL.
54 strtok (NULL, " \t");
56 BUGS
58 SEE ALSO
60 INTERNALS
62 ******************************************************************************/
64 static char * t;
66 if (str != NULL)
67 t = str;
68 else
69 str = t;
71 str += strspn (str, sep);
73 if (*str == '\0')
74 return NULL;
76 t = str;
78 t += strcspn (str, sep);
80 if (*t != '\0')
81 *t ++ = '\0';
83 return str;
84 } /* strtok */