strtok Scans s1 for the first token not contained in s2.
Syntax:
char *strtok(char *s1, const char *s2);
Prototype in:
string.h
Remarks:
strtok considers the string s1 to consist of a
sequence of zero or more text tokens,
separated by spans of one or more characters
from the separator string s2.
The first call to strtok returns a pointer to
the first character of the first token in s1
and writes a null character into s1
immediately following the returned token.
Subsequent calls with null for the first
argument will work through the string s1 in
this way, until no tokens remain.
The separator string, s2, can be different
from call to call.
Return Value:
strtok returns a pointer to the token found in
s1. A null pointer is returned when there are
no more tokens.
Portability:
strtok is available on UNIX systems and is
defined in ANSI C.
Example:
Code:
#include <string.h>
#include <stdio.h>
int main(void)
{
char input[16] = "abc,d";
char *p;
/* strtok places a NULL terminator
in front of the token, if found */
p = strtok(input, ",");
if (p) printf("%s\n", p);
/* A second call to strtok using a NULL
as the first parameter returns a pointer
to the character following the token */
p = strtok(NULL, ",");
if (p) printf("%s\n", p);
return 0;
}