Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

strrchr - Last occurrence of a character in a string

&pagelevel(4)&pagelevel

Definition

#include <string.h>

char *strrchr(const char *s, int c);

strrchr searches for the last occurrence of character c in string s and returns a pointer to
the located position in s if successful.

The terminating null byte (\0) is treated as a character.

Return val.

Pointer to the position of c in string s


if successful.

NULL pointer

if c is not contained in string s.

Notes

The strrchr and rindex functions are equivalent.

The following two prototypes of the strchr function are applicable to C++:
const char *strrchr(const char *s, int c);

char *strrchr( char *s, int c);

Example

Find the last ’s’:

#include <string.h>
#include <stdio.h>
int main(void)
{
   char *s = "What fun in the ssun!";
   printf("%s\n", s);
   printf("Where is the mistake? %s\n", strrchr(s, 's'));
   return 0;
}

See also

index, rindex, strchr