Name
strchr, strrchr
- locate character in string
Library
libc.lib
Synopsis
|
char *
strchr (const char *s, int c);
|
|
char *
strrchr (const char *s, int c);
|
Return values
The functions
strchr
and
strrchr
return a pointer to the located character, or
NULL
if the character does not appear in the string.
Detailed description
The
strchr
function locates the first occurrence of
c
(converted to a
char)
in the string pointed to by
s.
The terminating null character is considered part of the string;
therefore if
c
is
‘\0,’
the functions locate the terminating
‘\0.’
The
strrchr
function is identical to
strchr
except it locates the last occurrence of
c.
Examples
#include <string.h>
#include <stdio.h>
int main()
{
char one[50];
char* ret;
strcpy(one,"abcd");
ret = strchr("abcd", 'c');
if(!strncmp(one+2,ret,1)) printf("\ 'c\ ' found in string \"abcd\"\n");
ret = strchr(one, 'z');
if(ret == NULL) printf("\ 'z\ ' not found in string \"abcd\"\n");
return 0;
}
Output
’c’ found in string "abcd"
’z’ not found in string "abcd"
See also
memchr,
strcspn,
strpbrk,
strsep,
strspn,
strstr,
strtok
Feedback
For additional information or queries on this page send feedback
© 2005-2007 Nokia
|
|