Names specified here
Name Description Notes Source Availability
strtok() Tokenize string (·) <string.h> C89 C90 C95 C99 C11
strtok_s() Tokenize string ? (·) <string.h> C11
wcstok() Tokenize wide-character string (·) <wchar.h> C95 C99 C11
wcstok_s() Tokenize wide-character string ? (·) <wchar.h> C11
#include <string.h>
char *strtok(char *str, const char *toks);
#define __STDC_WANT_LIB_EXT1__ 1
#include <string.h>
char *strtok_s(char *str, rsize_t *strmaxp, const char *toks, char **sp);
#include <wchar.h>
wchar_t *wcstok(wchar_t *str, const wchar_t *toks, wchar_t **sp);
#define __STDC_WANT_LIB_EXT1__ 1
#include <wchar.h>
wchar_t *wcstok_s(wchar_t *str, rsize_t *strmaxp, const wchar_t *toks, wchar_t **sp);

Repeated calls to each of these functions modify a null-terminated string starting at str, breaking it into tokens terminated by the bytes or wide characters listed in the null-terminated string at toks as delimiters. On the first call, str must point to the string to be tokenized. On subsequent calls, str must be NULL, and the delimiters may change on each call. At the end of each call, each function remembers its position in the string being tokenized by storing it in *sp, except for strtok which uses internal storage, and so it might not be thread-safe.

On each call, each function scans the string from the current position (which is the start of the string on the first call) until it finds a non-delimiter or a null character. In the latter case, it returns NULL, indicating that there are no more tokens. Otherwise, it will return a pointer to the found character, after it has searched further for the first delimiter or null. If a delimiter is found, it will be overwritten with null, and the position for the next call will be set to point just after it. Otherwise, the position will be set to point to the null character.

On an initial call to strtok_s or wcstok_s, *strmaxp must be the maximum number of elements to be accessed in str, and must not be more than RSIZE_MAX. It will be modified by the initial and subsequent calls to indicate the number of remaining elements to be accessed.


CHaR
Sitemap Supported
Site format updated 2024-06-05T22:37:07.391+0000
Data updated 1970-01-01T00:00:00.000+0000
Page updated 2022-06-17T21:43:05.000+0000