beautypg.com

Strncpy, Strpbrk, Strncpy strpbrk – Zilog Z8F0130 User Manual

Page 492

background image

Appendix B. C Standard Library

UM013037-1212

468

Zilog Developer Studio II – Z8 Encore!
User Manual

int res;

res=strncmp(s1,s2,3);

strncpy

Copies not more than n characters from the string pointed to by s2 to the array pointed to
by s1. If copying takes place between objects that overlap, the behavior is undefined.

If the string pointed to by s2 is shorter than n characters, null characters are appended to
the copy in the array pointed to by s1, until n characters in all have been written.

Synopsis

#include

char *strncpy(char *s1, char *s2, size_t n);

Returns

The value of s1.

Example

char *ptr;

char s1[40]="Production";

char s2[]="Languages";

ptr=strncpy(s1,s2,4);

strpbrk

Locates the first occurrence in the string pointed to by s1 of any character from the string
pointed to by s2.

Synopsis

#include

char *strpbrk(char *s1, char *s2);

Returns

A pointer to the character, or a null pointer if no character from s2 occurs in s1.

Example

char *ptr;

char s1[]="COMPASS";

char s2[]="PASS";

ptr=strpbrk(s1,s2);