Chapter Contents |
Previous |
Next |
strchr |
Portability: | ISO/ANSI C conforming, UNIX compatible |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
CAUTION | |
EXAMPLE | |
RELATED FUNCTIONS | |
SEE ALSO |
SYNOPSIS |
#include <string.h> char *strchr(const char *str, int ch);
DESCRIPTION |
strchr
searches the null-terminated string
str
for the first occurrence of a specific character
ch
, returning a pointer to the first occurrence, or
NULL
if the character does not occur in the string.
RETURN VALUE |
The return value is a pointer to the first
occurrence of the character in the argument string, or
NULL
if the character is not found. If the search character is the
null character ('\0'), the return value addresses the null character at the
end of the argument string.
CAUTION |
A protection or addressing exception may occur if the argument string is not properly terminated.
See the memscntb function description for
information on possible interactions between the
strchr
,
memscntb
, or
strscntb
functions.
EXAMPLE |
#include <string.h> #include <stdio.h> main() { char *input; char *nl; input = "abcdefghijk\nlmnopqrstuvwxyz"; if (nl = strchr(input, '\n')) *nl = '\0'; printf("The new line character occurs after %c\n", *(nl-1)); }
RELATED FUNCTIONS |
memchr
,
stcpm
,
strpbrk
,
strrchr
,
strscan
,
strstr
SEE ALSO |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.