C语言第10讲讲述
#includestdio.h int main() { FILE *fp1,*fp2; // 打开两个文件进行操作 fp1=fopen(“11.2”,“r”); //第一个读 r read fp2=fopen(“D:\\c语言\\c源码\\write\\s002.txt”,“w”); // 第二个写 w int n,m,cnt=0; // 计数器初值0 scanf(“%d”,n); // 输入n for(int i=0;;i++) // 开始循环 {fscanf(fp1,“%d,”,m); //文件读取一个数给m if(mn){break;} //判断是否符合 要求 else { cnt++; //计算个数,用来5个换行 printf(“%d ”,m);fprintf(fp2,“%d ”,m);// 输出到屏幕,文件 if(cnt%5==0){printf(\n);fprintf(fp2,\n);} } } if(cnt%5!=0){printf(\n);fprintf(fp2,\n);} fclose(fp1); fclose(fp2); return 0; } 本讲主要介绍 C 语言中文件的基本类型及其相关操作 要求掌握 文件的打开、关闭 文件写入、读取 第十讲 文件 第十讲 文件 文件
原创力文档

文档评论(0)