Everything

strtok


Token division

[Classification]

Standard library

[Syntax]

#include <string.h>

char *strtok(char *s, const char *delimiters);

[Return value]

Returns a pointer to a token. If a token does not exist, the null pointer is returned.

[Description]

This function divides the character string indicated by s into strings of tokens by delimiting the character string with a character in the character string indicated by delimiters. If this function is called first, s is used as the first argument. Then, calling with the null pointer as the first argument continues. The delimiting character string indicated by delimiters can differ on each call. On the first call, the character string indicated by s is searched for the first character not included in the delimiting character string indicated by delimiters. If such a character is not found, a token does not exist in the character string indicated by s, and strtok returns the null pointer. If a character is found, that character is the beginning of the first token. After that, strtok searches from the position of that character for a character included in the delimiting character string at that time.

If such a character is not found, the token is expanded to the end of the character string indicated by s, and the subsequent search returns the null pointer. If a character is found, the subsequent character is overwritten by the null character (\0) indicating the termination of the token.