Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

strtok_r - split string into tokens (thread-safe)

&pagelevel(4)&pagelevel



Syntax

#include <string.h>

char *strtok_r(char *s, const char *sep, char **lasts); 

Description

The function strtok_r() is the thread-safe version of strtok().
The function strtok_r() can be used to split a complete string s terminated by a null into
0 or more substrings called "tokens". Tokens may be delimited by one or more separators
that are specified in the sep string. The lasts argument points to a pointer provided by the
user that strtok_r() uses to obtain the information necessary to continue processing this
string.

The first time strtok_r() is called, s points to a string terminated with a null byte, and sep
points to a string terminated with a null byte with delimiters. The value pointed to by lasts is
ignored. The function strtok_r() returns a pointer to the beginning of the first token
found, overwrites the first delimiter found with the NULL character (\0) and updates the
pointer pointed to by lasts.

To get additional tokens, a null pointer is specified for s and the value from the last call is
specified for lasts in the subsequent call. This can be continued until there are no more
tokens. In this case a null pointer is returned.

A different delimiter string sep may be specified in each call.

The function strtok_r() returns a pointer to the token. If no token was found, a null
pointer is returned.

Return val.

Pointer to the token found


if successful.

Null pointer

if no token is found.

See also

strtok(), string().