I have a file in which I'm trying to look for this sequence of bytes: 0xFF, 0xD8, 0xFF, and 0xE0. For right now, let's assume I'm only looking for 0xFF. I made this program for testing:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void analyzeFile(char* filename)
{
FILE* filePtr = fopen(filename, "rb");
int numImages = 0;
while (!feof(filePtr))
{
char bytes;
bytes = getc(filePtr);
printf("%c", bytes);
if ((bytes == 0xFF))
{
numImages++;
printf("image found!\n");
}
}
printf("%d\n", numImages);
}
This isn't working. When I call analyzeFile with parameter "test.txt", it prints the contents of the file out fine, but doesn't detect a single 0xFF byte:
contents of test.txt:
aÿØÿÿà1234
output:
aÿØÿÿà1234
0
for reference, 0xFF is equivalent to y-diaeresis, ÿ, according to ASCII.