STRTOK
Synopsis
#include <string.h>
char * strtok (char * s1, const char * s2)
Description
A number of calls to strtok() breaks the string s1 (which consists of a sequence of zero or more
text tokens separated by one or more characters from the separator string s2) into its separate
tokens.
The first call must have the string s1. This call returns a to the first character of the first
token, or NULL if no tokens were found. The inter-token separator character is overwrit- ten by a
null character, which terminates the current token.
For subsequent calls to strtok(), s1 should be set to a NULL . These calls start searching from the
end of the last token found, and again return a to the first character of the next token, or NULL
if no further tokens were found.
Example
#include <stdio.h>
#include <string.h>
void
main (void)
{
char * ptr;
char buf[] = " is a string of words." char * sep_tok = ",?! "
ptr = strtok(buf, sep_tok);
while(ptr != NULL) {
printf("s\n" ptr);
ptr = strtok(NULL, sep_tok);
}
}
Return Value
Returns a to the first character of a token, or a null if no token was found.
Note
The separator string s2 may be different from call to call.