STRTOK - obtain next token from string.

(ANSI Standard)

Usage:

#include <string.h>
ptr = strtok( s1, s2 );

Where:

char *s1;
is either NULL or points to a string from which tokens will be obtained (see below). This string will be changed by the action of "strtok".
const char *s2;
points to a string containing "separator characters", i.e. characters that may separate the tokens in the string being scanned. For example, if "s2" is the string "~\t", tokens in "s1" may be separated by either blanks or tab characters.
char *ptr;
points to the token obtained from the string being scanned. If there are no tokens left in the string, "strtok" returns the NULL pointer.

Description:

"strtok" obtains one token at a time from a string. The first call to "strtok" should pass a pointer to the string in the "s1" argument. Subsequent calls to obtain more tokens from the string should pass the NULL pointer as "s1". Between calls, "strtok" keeps a pointer in local static storage to remember where the last token was. The string of separators "s2" may be changed between calls.

When "strtok" finds a token in the string, it replaces the separator character at the end of the token with a "\0". In this way, the token looks just like a normal null-terminated string.

Notes:

Because this function uses a static storage area, it should not be called by code that needs to be re-entrant (e.g. exception handlers).

Copyright © 1996, Thinkage Ltd.