Function name : strrchr
Header file : <string.h>
Function prototype : char *strrchr(char *str, char c);
Function : Find the last occurrence of character c in the string.
Parameters : char *str is the target string to be retrieved
char c is the character to be retrieved
Return value : Returns the position of the last occurrence of character c in str. If the value is not found, the function returns a null pointer
Program example : Find the last occurrence of character 'c' in the string string and output the result
#include<string.h>#include<stdio.h>intmain(void){charstring[15];char*ptr,c='c';strcpy(string,www.dotcpp.com);ptr=strrchr( string,c);if(ptr){printf(Thecharacter%cisatposition:%dn,c,ptr-string);}else{printf(Thecharacterwasnotfoundn);}return0;}
Running results:
Thecharacteristic position:11