rindex() — Search for character

Standards

Standards / Extensions C or C++ Dependencies
XPG4.2
Single UNIX Specification, Version 3
both  

Format

#define  _XOPEN_SOURCE_EXTENDED 1
#include <strings.h>

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

General description

The rindex() function locates the last occurrence of c (converted to an unsigned char) in the string pointed to by string.

The string argument to the function must contain a NULL character (\0) marking the end of the string.

The rindex() function is identical to strrchr() — Find last occurrence of character in string.

Note: The rindex() function has been moved to the Legacy Option group in Single UNIX Specification, Version 3 and may be withdrawn in a future version. The strrchr() function is preferred for portability.

Returned value

If successful, rindex() returns a pointer to the first occurrence of c (converted to an unsigned character) in the string pointed to by string.

If c was not found, rindex() returns a NULL pointer.

There are no errno values defined.

Related information