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_ 1 #includeLIB_ EXT1__ <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_ 1 #includeLIB_ EXT1__ <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_
. It will be
modified by the initial and subsequent calls to indicate the
number of remaining elements to be accessed.