Guardian Native C Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)

Guardian Native C Library Calls (s) strtok(3)
NAME
strtok - Splits string into tokens
LIBRARY
G-series native Guardian processes: $SYSTEM.SYSnn.ZCRESRL
G-series native OSS processes: /G/system/sysnn/zcresrl
H-series and J-series native Guardian processes: $SYSTEM.ZDLLnnn.ZCREDLL
32-bit H-series and J-series OSS processes: /G/system/zdllnnn/zcredll
64-bit H-series and J-series OSS processes: /G/system/zdllnnn/ycredll
SYNOPSIS
#include <string.h>
char *strtok(
char *s1,
const char *s2);
PARAMETERS
s1 Contains a pointer to the string to be searched.
s2 Contains a pointer to the string of byte token delimiters.
DESCRIPTION
The strtok() function splits the string pointed to by the s1 parameter into a sequence of tokens,
each of which is delimited by a byte equal to one of the bytes in the s2 parameter.
Usually, the strtok() function is called repeatedly to extract the tokens in a string. The first time
the application program calls the strtok() function, it sets the s1 parameter to point to the input
string. The function returns a pointer to the first token. Then the application program calls the
function again with the s1 parameter set to the null pointer. This call returns a pointer to the next
token in the string. The application program repeats the call to strtok() with the s1 parameter set
to the null pointer until all the tokens in the string have been returned.
In the initial call to strtok(), the function first searches the string pointed to by the s1 parameter
to locate the first byte that does not occur in the delimiter string pointed to by the s2 parameter.
If such a byte is found, it is the start of the first token. The strtok() function then searches from
there for a byte that does occur in the delimiter string. If such a delimiter is found, strtok()
overwrites it with a null byte, which terminates the current token. The strtok() function saves a
pointer to the byte following the null byte and returns a pointer to the start of the token.
In the subsequent calls to strtok(), in which the s1 parameter is set to the null pointer, the func-
tion starts at its saved pointer and searches for the next byte that does not occur in the delimiter
string pointed to by the s2 parameter. If such a byte is found, it is the start of the new token. The
strtok() function then searches from there for a byte that does occur in the delimiter string. If
such a delimiter is found, strtok() overwrites it with a null byte, which terminates the new token.
The strtok() function saves a pointer to the byte following the null byte and returns a pointer to
the start of the new token.
If a call to the strtok() function cannot find a byte that does not occur in the delimiter string, it
returns the null pointer. If a call to the strtok() function cannot find the terminating byte that
does occur in the delimiter string, the current token extends to the end of the string and subse-
quent calls to strtok() will return the null pointer.
If the delimiters used in the string change from one set of characters to another within the string,
the application program can set the second parameter, s2, to different strings, from call to call.
The implementation behaves as though no function calls the strtok() function.
527192-018 Hewlett-Packard Company 6129