// a cursor variable, for positioning purposes
int cursor = 0;
// declare a counter
int counter = 0;
// start a loop
while (counter <= 0)
{
// get the cursor positioned correctly
fseek(fp, cursor, SEEK_SET);
// read the file and search for the jpeg key
JPG_KEY key;
fread(&key, sizeof(JPG_KEY), 4, fp);
// check the key to see if you are at the start of a jpeg
if( check_jpg_key(key) )
counter++;
cursor++;
}
For some reason, my "cursor" and "counter" variables a jumping to ridiculously high ints in the middle of this program instead of incrementing by 1 on each loop. With gdb, I found that the value for cursor jumps from 0 to 2099202 and the value for counter jumps from 0 to 3419700 at this line: fread(&key, sizeof(JPG_KEY), 4, fp);
Why?