#include<stdio.h>
int main(){
//读文件test.txt
//写文件test.bak
FILE * pfread=fopen("D:\\桌面\\test.txt","r");
if(pfread==NULL){
printf("打开文件test.txt失败\n");
return 1;
}
FILE * pfwrite=fopen("D:\\桌面\\test.bak","w");
if(pfwrite==NULL){
printf("打开文件test.bak失败\n");
//关闭上一个打开的文件
fclose(pfread);
return 1;
}
//读写文件内容--拷贝效果
//fgetc(); 读取文件的时候,如果遇到文件末尾或者读取失败会返回EOF
int ch=0;
while((ch=fgetc(pfread))!=EOF){
fputc(ch,pfwrite);
}
fclose(pfread);
pfread=NULL;
fclose(pfwrite);
pfwrite=NULL;
return 0;
}
c语言文件拷贝(简略)
最新推荐文章于 2024-08-31 18:18:12 发布