求解C语言编程: 文本文件abc.txt中有10个整数,编写程序,在屏幕上显示这10个数。

2025-03-22 22:28:38
推荐回答(1个)
回答1:

//测试可用
#include
int main()
{
    FILE *fout;
    if((fout=fopen("abc.txt","r"))==NULL)
    {
        printf("Cannot open this file!\n");
        return 0;
    }
    int temp;
    while(!feof(fout))
    {
        if(fscanf(fout,"%d",&temp)!=1)
            break;
        printf("%d ",temp);
    }
    return 0;
}
/*把这个c语言文件和abc.txt放在同一文件夹,然后编译运行,
如果指定路径请给出路径;望采纳*/