[C language library function source code]
[This program is compiled in Dev C ++ 4.9.9.2]
# Include <stdlib. h>
/*
Searches a string for a given character, which may be the null character '/0 '.
Find the location of the first occurrence of the CH in the string. If the string contains the CH character, the first occurrence is returned.
The pointer to the CH position; otherwise, null is returned.
*/
Char * my_strchr (const char * STR, int ch)
{
While (* STR & * Str! = (Char) CH)
STR ++;
If (* STR = (char) CH)
Return (char *) Str );
Return (null );
}
Int main ()
{
Char * STR = "ammana_babi ";
Char * P;
Char ch;
Ch = '9 ';
P = (char *) my_strchr (STR, CH );
If (P = NULL)
Printf ("can't find the character % C! /N ", CH );
Else
Printf ("find the character % C! /N ", * P );
Ch = 'B ';
P = (char *) my_strchr (STR, CH );
If (P = NULL)
Printf ("can't find the character % C! /N ", CH );
Else
Printf ("find the character % C! /N ", * P );
System ("pause ");
Return 0;
}