C Standard Libraries C++

wcsrchr()

Declaration

wchar_t* wcsrchr(const wchar_t* kwpString, wchar_t wChar);

Description

This function searches the wide-character string "kwpString" for the last instance of the character "wChar" and returns a pointer to the location in "kwpString" if the search was successful. Otherwise, a NULL pointer is returned to indicate that the character is not in the string.

Example

#include <cwchar>

int main()
{
    wchar_t waString[] = L"XoaX.net";
    wchar_t wChar = L'X';

    // Search a string for a character
    wchar_t* wpFound = wcsrchr(waString, wChar);
    wprintf(L"Searching \"%ws\" for the character \"%wc\"\n",
        waString, wChar);
    wprintf(L"Found \"%wc\" at index %d\n",
        wpFound[0], (int)(wpFound - waString));

    // Keep the window open until "Enter" is pressed
    getwchar();
    return 0;
}

Output

wcsrchr() Output
 

© 2007–2022 XoaX.net LLC. All rights reserved.