Syntax
#include <wchar.h> wchar_t *wcsrchr(const wchar_t *string, wint_t character);Description
wcsrchr locates the last occurrence of character in the string pointed to by string. The terminating wchar_t null character is considered to be part of the string.
wcsrchr returns a pointer to the character, or a NULL pointer if character does not occur in the string.
This example compares the use of wcschr and wcsrchr. It searches the string for the first and last occurrence of p in the wide character string.
#include <stdio.h>
#include <wchar.h>
#define SIZE 40
int main(void)
{
wchar_t buf[SIZE] = L"computer program";
wchar_t *ptr;
int ch = 'p';
/* This illustrates wcschr */
ptr = wcschr(buf, ch);
printf("The first occurrence of %c in '%ls' is '%ls'\n", ch, buf, ptr);
/* This illustrates wscrchr */
ptr = wcsrchr(buf, ch);
printf("The last occurrence of %c in '%ls' is '%ls'\n", ch, buf, ptr);
return 0;
/****************************************************************************
The output should be:
The first occurrence of p in 'computer program' is 'puter program'
The last occurrence of p in 'computer program' is 'program'
****************************************************************************/
}
Related Information