wcsrchr() — Locate Last Occurrence of Wide Character in String
Format
#include <wchar.h>
wchar_t *wcsrchr(const wchar_t *string, wchar_t character);
Language Level
ANSI
Threadsafe
Yes
Wide Character Function
See Wide Characters for more information.
Description
The wcsrchr()
function
locates the last occurrence of character in
the string pointed to by string. The ending wchar_t null
character is considered to be part of the string.
Return Value
The wcsrchr()
function
returns a pointer to the character, or a NULL pointer if character does
not occur in the string.
Example
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 wcsrchr */
ptr = wcsrchr( buf, ch );
printf( "The last occurrence of %c in '%ls' is '%ls'\n", ch, buf, ptr );
}
/**************** Output should be similar to: ******************
The first occurrence of p in 'computer program' is 'puter program'
The last occurrence of p in 'computer program' is 'program'
*/
Related Information
- strchr() — Search for Character
- strrchr() — Locate Last Occurrence of Character in String
- strcspn() — Find Offset of First Character Match
- strspn() — Find Offset of First Non-matching Character
- wcschr() — Search for Wide Character
- wcscmp() — Compare Wide-Character Strings
- wcscspn() — Find Offset of First Wide-Character Match
- wcsncmp() — Compare Wide-Character Strings
- wcswcs() — Locate Wide-Character Substring
- wcspbrk() — Locate Wide Characters in String
- <wchar.h>