Pointer to the null-terminated string to be tokenized. On subsequent calls, this should be `NULL` to continue tokenization of the same string.
2nd Parameter Type : const char *
Pointer to read-only string
2nd Parameter
Pointer to a null-terminated string containing the delimiter characters. These characters separate the tokens in `str`.
Read more about parameters of strtok in parameters section
The strtokfunction in C language Tokenizes a string into sequences separated by the delimiters specified.
The strtok function breaks a string into a sequence of zero or more nonempty tokens. On the first call, the string to be parsed should be specified in str. In each subsequent call that should parse the same string, str must be NULL. The delimiters used to identify token boundaries can be different from call to call.
The strtokfunction takes 2
parameters:
•
char * `str`: Pointer to the null-terminated string to be tokenized. On subsequent calls, this should be `NULL` to continue tokenization of the same string.
•
const char * `delim`: Pointer to a null-terminated string containing the delimiter characters. These characters separate the tokens in `str`.
Splits the string `str` into tokens using the characters in `delim` as delimiters. On the first call, `str` must be the input string to tokenize. On subsequent calls, `str` should be `NULL`. Returns a pointer to the next token or `NULL` if there are no more tokens.
The strtok function return value :
Returns a pointer to the next token, or NULL if there are no more tokens
Output
This example demonstrates basic usage of strtok to split a string into tokens based on a delimiter.