The C strrchr function is a String method, which returns a pointer to the last occurrence of a character in a given string. The syntax of the C strrchr function is
void *strrchr(const char *str, const char *chr_to_look);
- str: A valid string
- chr_to_look: Character value that you want to look inside str
strrchr in C Language Example
The strrchr function is used to find the last occurrence of a character within the user-specified string. Before using this method, you must include the #include<string.h> header.
This program will help you to understand the String Function with multiple C Programming examples.
#include <stdio.h> #include<string.h> int main() { char str[] = "This is abc working in abc company"; char *ch; ch = strrchr(str, 'b'); if(ch) { printf("We Found your Last Occurence of a Given Character"); printf("\nThe Final String From 'b' is : %s \n", ch); } else { printf("Given Character is Not found. Sorry!! \n"); } return 0; }