find the last occurrence of a character in a string
#include <string.h>
char *strrchr( const char *s, int c );
char __far *_fstrrchr( const char __far *s,
int c );
The strrchr() function locates the last occurrence of c (converted to a char) in the string pointed to by s. The terminating null character is considered to be part of the string.
The _fstrrchr() function is a data-model-independent form of the strrchr() function. It accepts far pointer arguments, and returns a far pointer. It is most useful in mixed memory model applications.
A pointer to the located character, or NULL if the character doesn't occur in the string.
#include <stdio.h>
#include <string.h>
void main()
{
printf( "%s\n", strrchr( "abcdeabcde", 'a' ) );
if( strrchr( "abcdeabcde", 'x' ) == NULL )
printf( "NULL\n" );
}
produces the output:
abcde NULL
strrchr() is ANSI; _fstrrchr() is WATCOM.
| Safety: | |
|---|---|
| Interrupt handler | Yes |
| Signal handler | Yes |
| Thread | Yes |