C Standard Libraries C++

wcscmp()

Declaration

int wcscmp(const wchar_t* kwpString1, const wchar_t* kwpString2);

Description

This function compares the two null-terminated wide-character strings "kwpString1" and "kwpString2" on a character by character basis to determine which one is less/greater alphabetically than the other. The function returns a value less than 0, equal to zero, or greater than zero, depending on whether the first string is less than, equal to, or greater than the second string, respectively.

Example

#include <cwchar>

int main()
{
    wchar_t waWideString1[] = L"XoaX.net";
    wchar_t waWideString2[] = L"Video Tutorials";

    // Compare String 1 and String 2
    int iComparison = wcscmp(waWideString1, waWideString2);
    wprintf(L"Comparison Value = %d\n", iComparison);
    // Compare String 1 with itself
    iComparison = wcscmp(waWideString1, waWideString1);
    wprintf(L"Comparison Value = %d\n", iComparison);
    // Compare String 2 and String 1
    iComparison = wcscmp(waWideString2, waWideString1);
    wprintf(L"Comparison Value = %d\n", iComparison);

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

Output

wcscmp() Output
 

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