例如,在打开文件并将记录读入数组之前,如何更好地判断二进制文件中有多少条记录?
MyFile = fopen("DATA.dat", "rb");
i = 0;
while (feof(MyFile) == 0) {
fread(&tempReadingRecord,sizeof(tempReadingRecord), 1, file);
if (feof(MyFile) == 0 {
i++;
}
}
fclose(MyFile);
}
printf("%d", i); /* does work to find out how many records but optimal? */