// 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++;
}
出于某种原因,我的“光标”和“计数器”变量在该程序中间跳转到高得离谱的整数,而不是在每个循环中递增 1。使用gdb,我发现在这一行光标的值从0跳转到2099202,计数器的值从0跳转到3419700: fread(&key, sizeof(JPG_KEY), 4, fp);
为什么?