strrchr()

Searches a string for the last occurrence of a character.

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

s

The string to search.

c

A character to search for.

Remarks

The strrchr() function searches for the last occurrence of c in the character array pointed to by s. The s argument must point to a null-terminated character array.

The function returns a pointer to the character found or returns a null pointer ( NULL) if it fails.

This facility may not be available on some configurations of the EWL.

Listing: Example of strrchr() Usage

#include <string.h>

#include <stdio.h>

int main(void)

{

const char *lastptr;

char s[] = "Carly Chuck";

lastptr = strrchr(s, 'C');

if (lastptr != NULL)

puts(lastptr);

return 0;

}

Output:

Chuck