Easy Tutorial
❮ C Function Log C Exercise Example85 ❯

C Library Function - strrchr()

C Standard Library - <string.h>

Description

The C library function char *strrchr(const char *str, int c) searches for the last occurrence of the character c (an unsigned char) in the string pointed to by the argument str.

Declaration

Here is the declaration for the strrchr() function.

char *strrchr(const char *str, int c)

Parameters

Return Value

The function returns a pointer to the last occurrence of the character c in the string str. If the value is not found, the function returns a null pointer.

Example

The following example demonstrates the use of the strrchr() function.

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

int main ()
{
   int len;
   const char str[] = "https://www.tutorialpro.org";
   const char ch = '.';
   char *ret;

   ret = strrchr(str, ch);

   printf("The string after |%c| is - |%s|\n", ch, ret);

   return(0);
}

Let's compile and run the above program, which will produce the following result:

The string after |.| is - |.com|

C Standard Library - <string.h>

❮ C Function Log C Exercise Example85 ❯