本文介绍了读取文件时出现问题...而(!feof(file))导致无限循环!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
void OpenFile() {
FILE *fp;
char buffer[1024];
int number;
fp=fopen("godess.txt","r");
if(fp==NULL){
printf("Error opening file!\n");
exit(0);
}
else {
while (!feof(fp)) {
printf("In loop!!!!");
fscanf(fp,"%d\n",&number);
}
fclose(fp);
}
}
你好...我正在尝试读取文件...但是在我写"while(!feof(fp))"的那一行中....它导致无限循环.... can任何人都请帮助我解决此问题..请我尝试了一切...但没有任何反应!!!
Hello...I'm trying to read a file ...but in the line where I write " while (!feof(fp))"....it leads in an infinite loop....can anyone please help me to solve this matter..Please I have tried everything...but nothing happens!!!
推荐答案
您应检查fscanf的返回值以查看其是否已成功读取数字.
You should check the return value of fscanf to see whether it has successfully read a number.
这篇关于读取文件时出现问题...而(!feof(file))导致无限循环!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!