[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
strchr() Find a Character in a String
#include <string.h> Required for declarations only
char *strchr(string,ch);
char *string; Source string
int ch; Character to be found
strchr() finds the occurrence of 'ch' in 'string. The terminating
null character ('\0') is included in the search. strchr() is case
sensitive.
Returns: A pointer to the character, if found, or NULL if it's not
found.
Notes: strchr() expects to operate on null-terminated strings.
No overflow checking is done when strings are copied or
appended.
-------------------------------- Example ---------------------------------
This example searches for a lowercase 'a' in 'str'.
#include <string.h>
#include <stdio.h> /* for printf */
char str[50] = "All in a good day's work.";
int ch = 'a';
char *rslt;
main()
{
if ((rslt = strchr(str,ch)) != NULL)
printf("character found: %c \n",*rslt);
else
printf("character not found.");
}
See Also:
strrchr()
strpbrk()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson