### strrchr -- Find Last Occurrence of Character in String

Format

>     #include <string.h>
>     char *strrchr(const char *string, int c);

Language Level: ANSI, POSIX, XPG4
strrchr finds the last occurrence of c (converted to a character) in string. The ending null character is considered part of the string.

Return Value
strrchr returns a pointer to the last occurrence of c in string. If the given character is not found, a NULL pointer is returned.

Example
This example compares the use of strchr and strrchr. It searches the string for the first and last occurrence of p in the string.

    #include <stdio.h>
    #include <string.h>

    #define SIZE 40

    int main(void)
    {
      char buf[SIZE] = "computer program";
      char * ptr;
      int    ch = 'p';

      /* This illustrates strchr */
      ptr = strchr( buf, ch );
      printf( "The first occurrence of %c in '%s' is '%s'\n", ch, buf, ptr );

      /* This illustrates strrchr */
      ptr = strrchr( buf, ch );
      printf( "The last occurrence of %c in '%s' is '%s'\n", ch, buf, ptr );

      /***********************************************************************
         The output should be:

         The first occurrence of p in 'computer program' is 'puter program'
         The last occurrence of p in 'computer program' is 'program'
      ***********************************************************************/
    }

strchr -- Search for Character
strcmp -- Compare Strings
strcspn -- Compare Strings for Substrings
strncmp -- Compare Strings
strpbrk -- Find Characters in String
strspn -- Search Strings
wcschr -- Search for Wide Character
wcspbrk -- Locate Wide Characters in String
wcsrchr -- Locate Wide Character in String
wcswcs -- Locate Wide-Character Substring
<string.h>