wcschr

Scans for a wide character in a specifed wide-character string.

Format

#include  <wchar.h>

wchar_t *wcschr  (const wchar_t *wstr, wchar_t
                 wc);
Function Variants This function also has variants named _wcschr32 and _wcschr64 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 first occurrence of a specified wide character in a null-terminated wide-character string. The terminating null character is considered to be part of the string. See also wcsrchr in this section.

Return Values
The address of the first 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
    
    main()
    {
        int  i;
        wchar_t  s1buf[BUFF_SIZE];
        wchar_t *status;
    
        /* Initialize the buffer */
    
        if (mbstowcs(s1buf, "abcdefghijkl lkjihgfedcba", BUFF_SIZE) == -1) {
            perror("mbstowcs");
            exit(EXIT_FAILURE);
        }
    
        /* This program checks the wcschr function by incrementally   */
        /* going through a string that ascends to the middle and then */
        /* descends towards the end.                                  */
    
        for (i = 0; (s1buf[i] != '\0') && (s1buf[i] != ' '); i++) {
            status = wcschr(s1buf, s1buf[i]);
            /* Check for pointer to leftmost character - test 1. */
            if (status != &s1buf[i]) {
                printf("Error in wcschr\n");
                exit(EXIT_FAILURE);
            }
        }
    
        printf("Test completed successfully\n");
    }
    

    When the example program is run, it produces the following result:

    Test completed successfully
    


Previous Page | Next Page | Table of Contents | Index