C examples for string.h:strrchr
function
<cstring> <string.h>
Locate last occurrence of character in string
const char * strrchr ( const char * str, int character ); char * strrchr ( char * str, int character );
Parameter | Description |
---|---|
str | C string. |
character | Character to be located. |
A pointer to the last occurrence of character in str. If not found, the function returns a null pointer.
#include <stdio.h> #include <string.h> int main ()/*from www. j a v a2 s.com*/ { char str[] = "This is a sample string"; char * pch; pch=strrchr(str,'s'); printf ("Last occurrence of 's' found at %d \n",pch-str+1); return 0; }