我很新的C和对这里显示文件的内容很简单的功能。它工作正常,除了我的文件的最后一行打印两次...我知道它必须做w/EOF,但我无法弄清楚如何让功能识别EOF作为最后一行,而不是再运行一次。我知道在互联网上有十亿个地方存在类似的问题,但是很多都是用于C++的,因为我是新手,我认为最好只使用我自己的代码。下面是代码:EOF阅读最后一行两次
{
int count=0, fileEnd=0;
FILE* rockPtr=fopen("rockact.txt", "r");
printf("\n%8s%8s%8s%8s%8s\n", "BANDID", "NAME", "SIZE", "CREW", "TRANS");
do
{
fileEnd=fscanf(rockPtr, "%d%s%d%d%s", &(tempBand.rockid), tempBand.bandname, &(tempBand.bandsize), &(tempBand.crewsize), tempBand.transport);
if (fileEnd !=EOF); //checks EOF has not been reached
{
printf("\n%8d%8s%8d%8d%8s", tempBand.rockid, tempBand.bandname, tempBand.bandsize, tempBand.crewsize, tempBand.transport);
count++;
}
}
while (fileEnd !=EOF);
fclose(rockPtr);
printf("\n The total amount of rock acts on file is %d\n", count);
}
非常感谢您的宝贵时间我很感激! – user2884601