正在加载图片...
例132将一个文件中的内容,复制到另一个文件中去。 第13章第4节 解:采用循环,从源文件中逐一读取一个字节内容,写入目标文件中,直到源文件结 束为止。 include stdio. h' maino FILE * fin, *fout char c char sourcefile 15, objectivefile 15: printf(n input sourcefile: i gets(sourcefile); if((fin=fopen(sourcefile, r"==NULL 打开源文件 Printf("in can not open source fileIn) exit(O);) printf("in input objectivefile: ) gets(objectivefile); if(fout=fopen(objectiveHle,W==NULL) 打开目标文件 printf("n can not open objectivefileIn) exit(0); while( feof(fin)==0) 判源文件是否结束 fe=fgetc(fin) 从源文件中逐个读内容,写入目标文件中 fputc(c, fout); fclose (fin); fclose(fout);例13.2 将一个文件中的内容,复制到另一个文件中去。 解:采用循环,从源文件中逐一读取一个字节内容,写入目标文件中,直到源文件结 束为止。 # include"stdio.h" main() {FILE *fin, *fout; char c; char sourcefile[15], objectivefile[15]; printf("\n input sourcefile: "); gets(sourcefile); if((fin=fopen(sourcefile,"r"))==NULL) {printf("\n can not open source file\n"); exit(0);} printf("\n input objectivefile: "); gets(objectivefile); if((fout=fopen(objectivefile,"w"))==NULL) {printf("\n can not open objectivefile\n"); exit(0);} while( feof(fin)==0) {c=fgetc(fin); fputc(c,fout);} fclose(fin); fclose(fout); } 判源文件是否结束 从源文件中逐个读内容,写入目标文件中 打开源文件 打开目标文件 第13章第4节
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有