Scans for the last occurrence of a wide-character in a given string.
#include <wchar.h>
wchar_t *wcsrchr (const wchar_t *wstr, wchar_t
wc);
Function Variants
This function also has variants named _wcsrchr32 and _wcsrchr64
for use with 32-bit and 64-bit pointer sizes, respectively. See
Section 1.8 for more information on using
pointer-size-specific functions.
See also wcschr in this section.
| x | The address of the last occurrence of the specified wide character. |
| NULL | Indicates that the wide character does not occur in the string. |
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#include <string.h>
#define BUFF_SIZE 50
#define STRING_SIZE 6
main()
{
int i;
wchar_t s1buf[BUFF_SIZE], w_string[STRING_SIZE];
wchar_t *status;
wchar_t *pbuf = s1buf;
/* Initialize the buffer */
if (mbstowcs(s1buf, "hijklabcdefg ytuhijklfedcba", BUFF_SIZE)
== -1) {
perror("mbstowcs");
exit(EXIT_FAILURE);
}
/* Initialize the string to be searched for */
if (mbstowcs(w_string, "hijkl", STRING_SIZE) == -1) {
perror("mbstowcs");
exit(EXIT_FAILURE);
}
/* This program checks the wcsrchr function by searching for the */
/* last occurrence of a string in the buffer s1buf and prints out */
/* the contents of s1buff from the location of the string found. */
status = wcsrchr(s1buf, w_string[0]);
/* Check for pointer to start of rightmost character string. */
if (status == pbuf) {
printf("Error in wcsrchr\n");
exit(EXIT_FAILURE);
}
printf("Test completed successfully\n");
printf("String found : [%S]\n", status);
}
Running the example produces the following result:
Test completed successfully String found : [hijklfedcba]