wcstok

Breaks a wide-character string into a sequence of tokens, each of which is delimited by a wide character code from another string.

Library:LibC
Classification:ANSI
Service:Characters and Strings

Syntax

  #include <wchar.h> 
   
  wchar_t  *wcstok (
     wchar_t         *ws1,
     const wchar_t   *ws2,
     wchar_t        **ptr);
  

Parameters

ws1

(IN) Points to the wide-character string to break into a sequence of tokens.

ws2

(IN) Points to the wide-character string containing the delimiter characters (tokens).

ptr

(OUT) Points to a pointer where the information is stored that is necessary for the function to continue scanning the same wide-character string.

Return Values

If a delimiter is found, returns a pointer to the first byte of a token. On subsequent iterations, if no delimiter is found, returns a NULL pointer.

If ws1 does not contain any of the delimiters specified in ws2, returns a pointer to ws1, and all of ws1 is considered to be a token.

Remarks

The wcstok function is used to break the string pointed to by ws1 into a sequence of tokens, each of which is delimited by a character from the string pointed to by ws2. The first call to wcstok returns a pointer to the first token in the string pointed to by ws1. On subsequent calls to wcstok, the first argument must be passed as a NULL pointer and the value in ptr is used to get the next token in the string.

The set of delimiters used in each of these calls to wcstok can be different from one call to the next. When a delimiter is found, it is overwritten by a null-terminating character, which terminates the current token.

Because wcstok can modify the original string, the string should be duplicated if the string is to be reused.

See Also