I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
ComputingCString.h

strrchr

Locate character in string
+ View other versions (3)

Interface

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

Description

The strrchr function locates the last occurrence of c (converted to a char) in the string s. If c is \0, strrchr locates the terminating \0.

Example:
Example - Locate character in string
Workings
#include <stdio.h>
#include <string.h>
int main()
{
  char s[20] = "01234560789";
  printf("The last position of '0' is %d.\n", strrchr(s, '0') - s);
  return 0;
}
Solution
Output:
The last position of '0' is 7.

Return Values

The strrchr function returns a pointer to the character, or a null pointer if c does not occur anywhere in s.

Standards

The strrchr function conforms to ISO/IEC 9899:1990 ("ISO C90").