Converts wide-character strings to tokens.
#include <string.h>
wchar_t *wcstok (WcString1, WcString2,ptr) wchar_t *WcString1; const wchar_t *WcString2; wchar_t **ptr
A sequence of calls to wcstok() breaks the wide-character string pointed to by WcString1 into a sequence of tokens, each of which is delimited by a wide-character code from the wide-character string pointed to by WcString2. The third argument points to a caller-provided wchar_t pointer into which the wcstok() function stores information necessary for it to continue scanning the same wide-character string.
The first call in the sequence has WcString1 as its first argument and is followed by calls with a nullpointer as their first argument. The separator string pointed to by WcString2 may be different from call to call.
The first call in the sequence searches the wide-character string pointed to by WcString1 for the first wide-character code that is not contained in the current separator string pointed to by WcString2. If no such wide-character code is found, then there are no tokens in the wide-character string pointed to by WcString1 and wcstok() returns a null pointer. If such a wide-character code is found, it is the start of the first token.
The wcstok() function then searches from there for a wide-character code that is contained in the current separator string. If no such wide-character code is found, the current token extends to the end of the wide-character string pointed to by WcString1, and subsequent searches for a token will return a null pointer. If such a wide-character code is found, it is overwritten by a null wide-character, which terminates the current token. The wcstok() function saves a pointer to the following wide-character code, from which the next search for a token will start.
Each subsequent call, with a null pointer as the value of the first argument, starts searching from the saved pointer and behaves as described above.
The implementation will behave as if no function calls wcstok().
WcString1 | Contains a pointer to the wide-character string to be searched. |
WcString2 | Contains a pointer to the string of wide-character token delimiters. |
Upon successful completion, the wcstok() function returns a pointer to the first wide-character code of a token. Otherwise, if there is no token, wcstok() returns a null pointer.
To convert a wide-character string to tokens, use the following:
#include <string.h> #include <locale.h> #include <stdlib.h>
main() { wchar_t *WCString1 = L"?a???b,,,#c"; wchar_t *pwcs ;
(void)setlocale(LC_ALL, ""); pwcs = wcstok(WCString1, L"?" ); /* pws points to the token L"a"*/ pwcs = wcstok((wchar_t *)NULL, L"," ); /* pws points to the token L"??b"*/ pwcs = wcstok( (wchar_t *)NULL, L"#," ); /* pws points to the token L"c"*/ }
This subroutine is part of Base Operating System (BOS) Runtime.
The wcschr subroutine, wcscspn subroutine, wcspbrk subroutine, wcsrchr subroutine, wcsspn subroutine, wcstod subroutine, wcstol subroutine, wcstoul subroutine, wcswcs subroutine.
The wchar.h file.
National Language Support Overview for Programming, Subroutines Overview, Understanding Wide Character String Search Subroutines in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.