Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

rindex - Last occurrence of a character in a string

&pagelevel(4)&pagelevel

Definition

#include <string.h>

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

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

The terminating null byte (\0) is also 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.

Note

Example

The rindex and strrchr functions are equivalent.

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", rindex(s, 's'));
   return 0;
}

See also

index, strchr, strrchr