I am writing code that compares 2 bytes which represent integers. I want to see if byte R is with +-10 of G. The problem I am having with the code is with the comparison in the if-statment near the end. The bytes never come out as being out of range, even when they should. I am sure the problem comes from how I am adding/subtracting the error_range, but I don't know any other way to do it.
I first considered converting the bytes into integers but I cannot find any help with that online. If that would work better than what I am doing here, please tell me how to do it.
Any help is appreciated!
const char ERROR_RANGE = 0x1010; //warning: overflow in implicit constant conversion
char R, G; /2 separate bytes
char buffer; //enough space for 1 byte
image = fopen(fileName,"r"); //open file
fread(&buffer, 1, 1, image); //read 1 byte
memcpy (&R,&buffer,1); //store it as R
fread(&buffer, 1, 1, image); //read 1 byte
memcpy (&G,&buffer,1); //store it as G
fclose(image);
if((R >= (G + ERROR_RANGE)) && (R <= (G - ERROR_RANGE)))
{
printf("Outside of range!\n");
}
Thanks.