C Language: strtok function
(Search String for Token)
In the C Programming Language, the strtok function splits s1 into a series of tokens using the delimiter s2. It returns a pointer to the first character of the token.
The strtok function marks the end of the token by storing a null character in s1 just after the last character in the token.
Syntax
The syntax for the strtok function in the C Language is:
char *strtok(char *s1, const char *s2);
Parameters or Arguments
- s1
- A string to search and break into tokens.
- s2
- A string containing the delimiter characters.
Returns
The strtok function returns a pointer to the first character of the token. If no token is found, a null pointer is returned.
You can find additional tokens in the same string using strtok(NULL, s2) because the strtok function continues the search begun by the previous strtok call.
Required Header
In the C Language, the required header for the strtok function is:
#include <string.h>
Applies To
In the C Language, the strtok function can be used in the following versions:
- ANSI/ISO 9899-1990
See Also
Other C functions that are noteworthy when dealing with the strtok function:
Advertisements