Table of contents
strrchr function in c
strrchr is a built-in function used to search for a last occurrence of the given character in a string.
This function is defined in string.h header file.
This function returns last occurrence of the character in a string else null if character not found.
Prototype
char *strrchr(const char *string,int m);
Parameters
This function takes one pointer and integer variable as input parameters.
Return value
This function returns last occurrence of a character in a string else null if not found.
strrchr in c example
//Example program for strrchr
#include<stdio.h>
#include<string.h>
int main()
{
const char string[]="scholarsoul";
const char a='o';
char *res;
res=strrchr(string,a);
printf("The last occurrence of given character is %s \n",res);
return 0;
}
Output
The last occurrence of given character is oul
Code explanation
The last occurrence of a given character is found by calling strrchr function and result is copied on to console.
People also ask for
What is strrchr?
strrchr is a built-in function used to search for a last occurrence of the given character in a string. It is defined in string.h header file.
People also read
- String in c programming
- C pointers
- strchr in c
- strtol in c
- strtod in c
- Popular c functions upgrad
- strncpy in c
- strcpy in c
- strcmp in c
- strrev in c
- strstr in c