Defined in
string.h.
Find last occurrence of character in string.
Returns the last occurrence of c in string.
The null-terminating character is included as part of the string and can also be searched.
Parameters.
- string Null-terminated string scanned in the search.
- c
Character to be found.
Return Value.
- If character is found, a pointer to the last occurrence of c in string is returned.
- If not, NULL is returned.
Portability.
- Defined in ANSI-C.
- ANSI-C++ standard specifies two different declarations for this function instead of the one included in ANSI-C:
const char * strrchr ( const char * string, int c );
char * strrchr ( char * string, int c );
Both have the same behavior as the original declaration.
Example.
/* strrchr example */
- include
- include
int main ()
{
char str[] = "This is a sample string";
char * pch;
pch=strrchr(str,'s');
printf ("Last occurence of 's' found at %d \n",pch-str+1);
return 0;
}
Output:
Last occurrence of 's' found at 18
See also.
strchr, strcspn, strcmp, strstr, memchr
From
http://www.cplusplus.com/ref/