|
VMS Help CRTL, strtok, Description *Conan The Librarian |
The strtok function locates text tokens in a given string. The
text tokens are delimited by one or more characters from a
separator string that you specify. The function keeps track of
its position in the string between calls and, as successive calls
are made, the function works through the string, identifying the
text token following the one identified by the previous call.
A token in s1 starts at the first character that is not a
character in the separator string s2 and ends either at the end
of the string or at (but not including) a separator character.
The first call to the strtok function returns a pointer to the
first character in the first token and writes a null character
into s1 immediately following the returned token. Each subsequent
call (with the value of the first argument remaining NULL)
returns a pointer to a subsequent token in the string originally
pointed to by s1. When no tokens remain in the string, the strtok
function returns a NULL pointer. (This can occur on the first
call to strtok if the string is empty or contains only separator
characters.)
Since strtok inserts null characters into s1 to delimit tokens,
s1 cannot be a const object.
The strtok_r function is the reentrant version of strtok. The
function strtok_r considers the null-terminated string s as a
sequence of zero or more text tokens separated by spans of one or
more characters from the separator string sep. The lasts argument
points to a user-provided pointer to stored information needed
for strtok_r to continue scanning the same string.
In the first call to strtok_r, s points to a null-terminated
string, sep points to a null-terminated string of separator
characters, and the value pointed to by lasts is ignored. The
strtok_r function returns a pointer to the first character of
the first token, writes a null character into s immediately
following the returned token, and updates the pointer to which
lasts points.
In subsequent calls, s is a NULL pointer and lasts is unchanged
from the previous call so that subsequent calls move through the
string s, returning successive tokens until no tokens remain. The
separator string sep can be different from call to call. When no
token remains in s, a NULL pointer is returned.
|
|