《程序设计基础实训指导教程-c语言》ISBN 978-7-03-032846-5p1988.1.2 上级实训内容
【实训内容2】将磁盘上的一个文本文件的内容复制到另一个文件中
#include<stdio.h>#include<stdlib.h>#include<string.h>int main(){FILE *fp1,*fp2;if((fp1=fopen("string.txt","r"))==NULL){printf("file open error\n");exit(0);}if((fp2=fopen("new.txt","w"))==NULL){printf("file open error\n");exit(0);}char str;while((str=getc(fp1))!=EOF){fputc(str,fp2);}fclose(fp1);fclose(fp2);if((fp2=fopen("new.txt","r"))==NULL){printf("file open error\n");exit(0);}while ((str=getc(fp2))!=EOF){putchar(str);}putchar('\n');}