1WCSTOK(3) Linux Programmer's Manual WCSTOK(3)
2
3
4
6 wcstok - split wide-character string into tokens
7
9 #include <wchar.h>
10
11 wchar_t *wcstok(wchar_t *wcs, const wchar_t *delim, wchar_t **ptr);
12
14 The wcstok() function is the wide-character equivalent of the strtok(3)
15 function, with an added argument to make it multithread-safe. It can
16 be used to split a wide-character string wcs into tokens, where a token
17 is defined as a substring not containing any wide-characters from de‐
18 lim.
19
20 The search starts at wcs, if wcs is not NULL, or at *ptr, if wcs is
21 NULL. First, any delimiter wide-characters are skipped, that is, the
22 pointer is advanced beyond any wide-characters which occur in delim.
23 If the end of the wide-character string is now reached, wcstok() re‐
24 turns NULL, to indicate that no tokens were found, and stores an appro‐
25 priate value in *ptr, so that subsequent calls to wcstok() will con‐
26 tinue to return NULL. Otherwise, the wcstok() function recognizes the
27 beginning of a token and returns a pointer to it, but before doing
28 that, it zero-terminates the token by replacing the next wide-character
29 which occurs in delim with a null wide character (L'\0'), and it up‐
30 dates *ptr so that subsequent calls will continue searching after the
31 end of recognized token.
32
34 The wcstok() function returns a pointer to the next token, or NULL if
35 no further token was found.
36
38 For an explanation of the terms used in this section, see at‐
39 tributes(7).
40
41 ┌──────────┬───────────────┬─────────┐
42 │Interface │ Attribute │ Value │
43 ├──────────┼───────────────┼─────────┤
44 │wcstok() │ Thread safety │ MT-Safe │
45 └──────────┴───────────────┴─────────┘
47 POSIX.1-2001, POSIX.1-2008, C99.
48
50 The original wcs wide-character string is destructively modified during
51 the operation.
52
54 The following code loops over the tokens contained in a wide-character
55 string.
56
57 wchar_t *wcs = ...;
58 wchar_t *token;
59 wchar_t *state;
60 for (token = wcstok(wcs, " \t\n", &state);
61 token != NULL;
62 token = wcstok(NULL, " \t\n", &state)) {
63 ...
64 }
65
67 strtok(3), wcschr(3)
68
70 This page is part of release 5.10 of the Linux man-pages project. A
71 description of the project, information about reporting bugs, and the
72 latest version of this page, can be found at
73 https://www.kernel.org/doc/man-pages/.
74
75
76
77GNU 2020-06-09 WCSTOK(3)