C Standard Libraries C++

wmemcmp()

Declaration

int wmemcmp(const wchar_t* kwpBuffer1,
            const wchar_t* kwpBuffer2,
            size_t uiCompSize);

Description

This function compares the first "uiCompSize" wide-characters of each of the buffers "kwpBuffer1" and "kwpBuffer2" and returns an integer that is less than 0 if "kwpBuffer1" is less than "kwpBuffer2," 0 if "kwpBuffer1" is equal to "kwpBuffer2," and less than 0 if "kwpBuffer1" is greater than "kwpBuffer2."

Example

#include <cwchar>

int main()
{
    wchar_t waBuffer1[] = L"XoaXAlgorithms";
    wchar_t waBuffer2[] = L"XoaXArchitecture";
    size_t uiCompSize = 5;

    // Compare the first 5 characters (should be the same)
    wprintf(L"The first %u characters of \"%ws\" vs \"%ws\"\n",
        uiCompSize, waBuffer1, waBuffer2);
    int iCompValue = wmemcmp(waBuffer1, waBuffer2, uiCompSize);
    wprintf(L"Comparison value = %d\n", iCompValue);

    // Increase the number of characters to compare
    uiCompSize = 6;
    wprintf(L"The first %u characters of \"%ws\" vs \"%ws\"\n",
        uiCompSize, waBuffer1, waBuffer2);
    iCompValue = wmemcmp(waBuffer1, waBuffer2, uiCompSize);
    wprintf(L"Comparison value = %d\n", iCompValue);

    // Reverse the order of comparison
    wprintf(L"The first %u characters of \"%ws\" vs \"%ws\"\n",
        uiCompSize, waBuffer2, waBuffer1);
    iCompValue = wmemcmp(waBuffer2, waBuffer1, uiCompSize);
    wprintf(L"Comparison value = %d\n", iCompValue);

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

Output

wmemcmp() Output
 

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