1
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);
    }
}

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!!!

4

1 回答 1

2

您应该检查 fscanf 的返回值,看它是否成功读取了一个数字。

于 2011-06-03T19:25:32.063 回答