C++ memcmp fails with unsigned char array?
سؤال
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.
لا تنتمي إلى StackOverflow