strtok function(Search String for Token) in C Language – example and detail

In the C Programming Language, the strtok feature splits s1 into a sequence of tokens the usage of the delimiter s2. It returns a pointer to the first persona of the token.

The strtok feature marks the stop of the token by storing a null personality in s1 just after the final character in the token.


The syntax for the strtok characteristic in the C Language is:

char *strtok(char *s1, const char *s2);

Parameters or Arguments

s1 A string to search and wreck into tokens. s2 A string containing the delimiter characters.


The strtok characteristic 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 the usage of strtok(NULL, s2) due to the fact the strtok characteristic continues the search begun by means of the previous strtok call.

Required Header

In the C Language, the required header for the strtok feature is:

#include <string.h>

Applies To

In the C Language, the strtok feature can be used in the following versions:

ANSI/ISO 9899-1990

See Also

Other C features that are noteworthy when dealing with the strtok function:

memchr feature strchr function strpbrk function strrchr characteristic strstr function