[C language library function source code]
[This program is compiled in Dev C ++ 4.9.9.2]
/*
Finds the last occurrence of CH in string. The terminating null character is used as part of the search.
Find the location where the character 'ch' is the last time in the string. If the STR contains the CH character, the pointer at the CH position is returned; otherwise, null is returned.
*/
# Include <stdlib. h>
Char * my_strrchr (const char * STR, int ch)
{
Char * P = (char *) STR;
While (* Str) STR ++;
While (Str --! = P & * Str! = (Char) CH)
;
If (* STR = (char) CH)
Return (char *) Str );
Return (null );
}
Int main ()
{
Char * STR = "ammana_babi ";
Char * P;
Char ch;
Ch = '9 ';
P = (char *) my_strrchr (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_strrchr (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;
}