I am generating a random number and checking if the character contained is a certain character (i.e. 0xDB). This doesn’t seem to be the correct way to do it as it seems like my if() is always false and goes to else.
How can I achieve this? Code below. Thanks!
if(buffer[randomNumber] == 0xDB)
count++;
else {
buffer[randomNumber] = 0xDB;
arrayChangeFlag++;
count++;
}
What is the type of
buffer?I guess that it is either
signed charor implicitly-signedchar. The range of a signed char in most implementations is (-128,+127).0xDBis outside that range, so that equality test might never be true.Try changing the type of buffer to
unsigned char, or replacing your test with:or