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.");
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster