C Standard Libraries C++

memcmp()

Declaration

int memcmp(const void* kvpBuf1, const void* kvpBuf2, size_t qCount);

Description

This function compares the first "qCount" char values in two buffers, "kvpBuf1" and "kvpBuf2," and returns: a value less than zero if the first buffer is less than the second, zero if the buffers are the same, and a number greater than zero if first buffer is greater. For the purposes of comparison, the one buffer is greater than the other if it has the first larger char value.

Example

#include <cstdio>
#include <cstring>

int main()
{
    char caBuffer1[] = "XoaX.net";
    char caBuffer2[] = "XoaXDotNet";
    int iComp = memcmp(caBuffer1, caBuffer2, 8);

    printf("Comparison value: %i\n", iComp);
    // Print out a message based on the comparison value.
    if (iComp < 0) {
        printf("%s < %s\n", caBuffer1, caBuffer2);
    } else if (iComp > 0) {
        printf("%s > %s\n", caBuffer1, caBuffer2);
    } else {
        printf("%s == %s\n", caBuffer1, caBuffer2);

    }
    return 0;
}

Output

memcmp() Output
 

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