#include <string.h>
char *strtok (
char *str, /* string to scan & delimit */
const char *set); /* set of delimeters */
Description
A sequence of calls to strtok split str into tokens.
A token is a character sequence separated by a single character
delimiter that is part of the string set.
On the first call str is a non-NULL string pointer whose
first character is used as the starting location to scan for
tokens.
The strtok function begins searching the string str
for the first delimiter character that is part of set. This
end of the token is automatically replaced by a null-character
by the function, and the beginning of the token is returned by
the function. The end location is a saved pointer for subsequent
calls.
In subsequent calls, when str is a NULL pointer, the
strtok function searches from the saved pointer and uses
therefore position right after the end of last token as the new
starting location for scanning. The token delimiters pointed to by
set may be different from call to call.
Return Value
The strtok function returns a pointer to the first
character of the next token from str. If there are no further
tokens, a NULL pointer is returned.
Note that the contents of the string str are modified and
broken into smaller strings (tokens).
Example
#include <string.h>
#include <stdio.h> /* for printf */
void tst_strtok (void) {
char *tok;
tok = strtok ("This is a string of text", " \t\n");
while (tok != NULL) {
printf ("Token: %s\n", tok);
tok = strtok (NULL, " \t\n");
}
}
This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.
ARM websites use two types of cookie: (1) those that enable the site to function and perform as required; and (2) analytical cookies which anonymously track visitors only while using the site. If you are not happy with this use of these cookies please review our Privacy Policy to learn how they can be disabled. By disabling cookies some features of the site will not work.