beautypg.com

Strtok – Zilog EZ80F916 User Manual

Page 391

background image

UM014423-0607

C Standard Library

ZiLOG Developer Studio II

eZ80Acclaim!

®

User Manual

371

value causes underflow, zero is returned and the macro

errno

acquires the value

ERANGE.

Example

char *ptr;
char s[]="0.1456";
double res;
res=strtod(s,&ptr);

strtok

A sequence of calls to the

strtok

function breaks the string pointed to by s1 into a

sequence of tokens, each of which is delimited by a character from the string pointed to by
s2. The first call in the sequence has s1 as its first argument, and is followed by calls with
a null pointer as their first argument. The separator string pointed to by s2 can be different
from call to call.

The first call in the sequence searches s1 for the first character that is not contained in the
current separator string s2. If no such character is found, there are no tokens in s1, and the

strtok

function returns a null pointer. If such a character is found, it is the start of the

first token.

The

strtok

function then searches from there for a character that is contained in the cur-

rent separator string. If no such character is found, the current token extends to the end of
the string pointed to by s1, and subsequent searches for a token fail. If such a character is
found, it is overwritten by a null character, which terminates the current token. The

strtok

function saves a pointer to the following character, from which the next search for

a token starts.

Each subsequent call, with a null pointer as the value of the first argument, starts searching
from the saved pointer and behaves as described in the preceding paragraphs.

Synopsis

#include
char *strtok(char *s1, char *s2);

Returns

A pointer to the first character of a token or a null pointer if there is no token.

Example

#include
static char str[] = "?a???b, , ,#c";
char *t;
t = strtok(str,"?"); /* t points to the token "a" */
t = strtok(NULL,","); /* t points to the token "??b " */

This manual is related to the following products: