猿问

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

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


POPMUISE
浏览 617回答 2
2回答

九州编程

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

拉丁的传说

运行前在C盘 的根目录下建立一个data.txt的文件#include <stdio.h>int main(){FILE *f;int i[10], j, m = 0, n = 0;f = fopen("c:/data.txt", "r");if(f == NULL){printf("open file error!");return 0;}for(j = 0; j < 10; j++){fscanf(f, "%d", i + j);}for(j = 1, m = i[0], n = i[0]; j < 10 - 1; j++){if(m < i[j])m = i[j];if(n > i[j])n = i[j];}printf("%d %d", m, n);return 0;}
随时随地看视频慕课网APP
我要回答