strrchr() Scan String for Last Occurrence of Character
#include <string.h> Required for declarations only
char *strrchr(string,ch);
char *string; Search string
int ch; Character to be located
strrchr() scans 'string' in a reverse direction, looking for the last
occurrence of the character 'ch'. The terminating null character
('\0') is included in the search.
Returns: A pointer to the last occurrence of 'ch in 'string. If
the character is not found in 'string', a NULL pointer is
returned.
-------------------------------- Example ---------------------------------
The following statements find the last occurrence of 'ch' in
'string'.
#include <string.h>
#include <stdio.h>
char *string = "How now, brown cow.";
int ch = 'b';
char *rslt;
main()
{
if ((rslt = strrchr(string,ch)) != NULL)
printf("character found: %c\n",*rslt);
else
printf("character not found.\n");
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster