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 - split string into tokens

&pagelevel(4)&pagelevel

Syntax

#include <string.h>

char * strtok(char *s1, const char *s2);

Description

strtok() can be used to split a complete string s1 into substrings called "tokens", e.g. a sentence into individual words, or a source program statement into its smallest syntactical units. The pointer to s1 may only be passed in the first call to strtok(); subsequent calls must be specified with a null pointer.

The start and end criterion for each token are separator characters (delimiters), which must be specified in a second string s2. Tokens may be delimited by one or more such separators or by the beginning and end of the entire string s1. Blanks, colons, commas, etc., are typical separators between the words of a sentence.

strtok() processes exactly one token per call. The first call returns a pointer to the beginning of the first token found. Each subsequent call returns a pointer to the beginning of the next token. strtok() terminates each token with the null byte (\0).

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

strtok() is not thread-safe. Use the reentrant function strtok_r() when needed.

Return val.

Pointer to the start of a token.

A pointer to the first token is returned at the first call; a pointer to the next token at the next call, and so on. strtok() terminates each token in s1 with a null byte (\0) by overwriting the first found delimiter in each case with \0.

Null pointer, if no token, or no further token was found.

See also

string.h., strtok_r().