INtime SDK Help
strtok, strtok_s, wcstok, wcstok_s

Finds the next token in a string.

#include <string.h>

char *strtok (char *string1, const char *string2);
char *strtok_s(char *string1, const char *string2, char **context);

#include <wchar.h>

wchar_t *wcstok(wchar_t *string1, const wchar_t *string2, wchar_t **context);
_wchar_t *wcstok(wchar_t *string1, const wchar_t *string2);
wchar_t *wcstok_s(wchar_t *string1 const wchar_t *string2, wchar_t **context);


String containing token(s); may be separated by one or more of the delimiters from string2.
Set of delimiter characters.
Used to store position information between calls to strtok_s/wcstok_s.


This function reads string1 as a series of zero or more tokens and string2 as the set of characters serving as delimiters of the tokens in string1.

Use a series of calls to strtok to break out tokens from string1. In the first call, strtok searches for the first token in string1, skipping leading delimiters. To read the next token from string1, call strtok with a null pointer value for the string1 argument. The null pointer argument causes strtok to search for the next token in the previous token string. The set of delimiters may vary from call to call, so string2 can take any value.

Calls to this function will modify string1, since each time strtok is called it inserts a null character \0 after the token in string1.

strtok_s is a safer version of strtok. It validates its parameters. If string2 or context is a NULL pointer, or context points to a NULL pointer when string1 is a NULL pointer, then the function returns NULL and sets errno to EINVAL.

wcstok and wcstok_s are wide-character versions of the functions. _wcstok is a non-standard wide-chacater version of strtok, used by the generic text macro _tcstok.

Return Values

A pointer to the first token in string1 the first time strtok is called. All tokens are null-terminated.
A pointer to the next token in the string on subsequent calls with the same token string.
A null pointer; there are no more tokens.

Generic Text Routines

tchar.h routine _UNICODE not defined _UNICODE defined
_tcstok strtok _wcstok
_tcstok_s strtok_s wcstok_s


Versions Defined in Include Link to
INtime 3.0
INtime 6.0 (for wide-character and generic text versions)
See Also