wcsrchr

Scans for the last occurrence of a wide-character in a given string.

Format

#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.

Arguments

wstr
A pointer to a null-terminated wide-character string.
wc
A character of type wchar_t.

Description

This function returns the address of the last occurrence of a given wide character in a null-terminated wide-character string. The terminating null character is considered to be part of the string.

See also wcschr in this section.

Return Values
The address of the last occurrence of the specified wide character. 
NULL  Indicates that the wide character does not occur in the string. 

Example

    #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]
    


Previous Page | Next Page | Table of Contents | Index