I have been trying to figure out what has been the problem now for a while but I can't.
When I run GDB, it is telling me that compare[0]
is either 97
, 235
, 82
or 0
.
int counter = 0;
FILE* inptr = fopen("card.raw", "r");
BYTE compare[512];
fread(&compare, 512, 1, inptr);
while (!feof(inptr)) {
if ((compare[0] == 0xff) && (compare[1] == 0xd8) && (compare[2] == 0xff) && (compare[3] == 0xe0 || compare[3] == 0xe1)) {
char filename[9];
sprintf(filename, "%03d", counter);
sprintf(filename, "%s", ".jpeg");
FILE* outptr = fopen(filename,"w");
fwrite(&compare, 512, 1, outptr);
fread(&compare, 512, 1, inptr);
while ((compare[0] != 0xff) && (compare[1] != 0xd8) && (compare[2] != 0xff) && (compare[3] != 0xe0 || compare[3] != 0xe1)) {
fwrite(&compare, 512, 1, outptr);
fread(&compare, 512, 1, inptr);
}
fclose(outptr);
counter++;
}
fread(&compare, 512, 1, inptr);
}
fclose(inptr);
I know compare[0 or 2]
should be 255
, compare[1]
should be 216
, and that compare[3]
should be 224
or 225
but it won't show that. I also ran valgrind and nothing was wrong.
Am I opening the file correctly or is there something wrong with fread
?