简体   繁体   中英

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.

当缓冲区比较相等时,该函数返回 (即不为true)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM