beautypg.com

Strstr function, Strtok function, Strstr – Zilog Z80380 User Manual

Page 85: Strtok

background image

UM004001-COR1103

4–21

Run Time Environment

Library Functions

strstr

FUNCTION

Header file statement:

#include

Syntax:

char *strstr

( const char *string1, const char *string2 )

The strstr function returns a pointer to the first occurrence of string2 in string1.

Return Value

This function returns either a pointer to the first occurrence of string2 in string1, or NULL if
it does not find the string.

strtok

FUNCTION

Header file statement:

#include

Syntax:

char *strtok

(char *string1, const char *string2)

The strtok function reads string1 as a series of zero or more tokens and string2 as the set of
characters serving as delimiter of the tokens in string1. The tokens in string1 may be sepa-
rated by one or more of the delimiters from string2.

The tokens can be broken out of string1 by a series of calls to strtok. In the first call to strtok
for string1, strtok searches for the first token in string1, skipping leading delimiters. A
pointer to the first token is returned. To read the next token from string1, call strtok with a
NULL value for the string1 argument. The NULL string1 argument causes strtok to search
for the next token in the previous token string. The set of delimiters may vary from call to
call, so string2 can take any value.

Note that calls to this function modify string1, because each time strtok is called it inserts a
null character (‘\0’) after the token in string1.

Parameter

Description

string1

Searched string

string2

String to search for

Parameter

Description

string1

String containing token(s)

string2

Set of delimiter characters