C strrchr Function

The C strrchr function is a String Function, which returns a pointer to the last occurrence of a character in a given string. The syntax of the strrchr in C Programming language 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 used to find the last occurrence of a character within the user-specified string. You have to include the #include<string.h> header before using this strrchr String Function.

This program will help you to understand the strrchr String Function with multiple C Programming examples.

/* C strrchr Function example */
 
#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;
}
C strrchr function example