wcstok, wcstok_s

Header: <wchar.h>

  1. Finds the next token in a null-terminated wide string pointed to by str. The separator characters are identified by null-terminated wide string pointed to by delim.

# Declarations

wchar_t* wcstok( wchar_t* str, const wchar_t* delim, wchar_t** ptr );

(since C95) (until C99)

wchar_t* wcstok( wchar_t* restrict str, const wchar_t* restrict delim,
wchar_t** restrict ptr );

(since C99)

wchar_t* wcstok_s( wchar_t* restrict str, rsize_t* restrict strmax,
const wchar_t* restrict delim, wchar_t** restrict ptr);

(since C11)

# Parameters

# Return value

Returns pointer to the beginning of the next token or null pointer if there are no more tokens.

# Example

#include <stdio.h>
#include <wchar.h>
 
int main(void)
{
    wchar_t input[] = L"A bird came down the walk";
    printf("Parsing the input string '%ls'\n", input);
    wchar_t* buffer;
    wchar_t* token = wcstok(input, L" ", &buffer);
    while (token)
    {
        printf("%ls\n", token);
        token = wcstok(NULL, L" ", &buffer);
    }
 
    printf("Contents of the input string now: '");
    for (size_t n = 0; n < sizeof input / sizeof *input; ++n)
        input[n] ? printf("%lc", input[n]) : printf("\\0");
    puts("'");
}

# See also