I have two char buffers that I am trying to compare with them. I have a strange problem. I have the following code:
char buffer1[50], buffer2[60];
for(int i = 0; i < 20; i++)
{
if(buffer1[15+i] != buffer2[25+i])
{
printf("%c", buffer1[15+i]);
printf("%c", buffer2[25+i]);
printf("%02x", (unsigned char)buffer1[15+i]);
printf("%02x", (unsigned char)buffer2[25+i]);
break;
}
}
The code above is a simplified version of my actual code, which I have not copied here because it is too long. Just in case this can help, I got these two buffers over the network, reading sockets.
The problem is breaking the loop, even when both buffers are the same. To check what is in the buffers, I added two print statements inside the if statement. And oddly, printf statements print the same value for% c and% 02x, but the comparison fails and the loop breaks.
source
share