I got a probably small problem using memcmp. I have two arrays (length = 3 byte) with exactly the same data.

If I try to compare them with memcmp, it fails?!

if (memcmp(ucbuffer, ucnewbuffer, buffer.sDeviceData.sLenght)) {
    cout << "val written, val ok!\n";
};

ucbuffer, ucnewbuffer are both unsigned char * and were allocated using

calloc(buffer.sDeviceData.sLenght, sizeof(unsigned char);

If i compare both arrays by hand, both it will result in being exactly the same.

Do you have any Idea?

Have a nice evening.

有帮助吗?

解决方案

That function returns zero (i.e., not true) when the buffers compare equal.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top