beautypg.com

Strchr, Strcmp, Strcpy – Zilog Z8F0130 User Manual

Page 489: Strchr strcmp strcpy

background image

UM013037-1212

strchr

Zilog Developer Studio II – Z8 Encore!

User Manual

465

strchr

Locates the first occurrence of c (converted to a

char

) in the string pointed to by s. The

terminating null character is considered to be part of the string.

Synopsis

#include

char *strchr(char *s, int c);

Returns

A pointer to the located character, or a null pointer if the character does not occur in the
string.

Example

char *ptr;

char str[]="COMPASS";

ptr=strchr(str,'p');

strcmp

Compares the string pointed to by s1 to the string pointed to by s2.

Synopsis

#include

int strcmp(char *s1, char *s2);

Returns

An integer greater than, equal to, or less than zero, according as the string pointed to by s1
is greater than, equal to, or less than the string pointed to by s2.

Example

char s1[]="Production";

char s2[]="Programming";

int res;

res=strcmp(s1,s2);

strcpy

Copies the string pointed to by s2 (including the terminating null character) into the array
pointed to by s1. If copying takes place between objects that overlap, the behavior is unde-
fined.