69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
int main(void) {
FILE* fp1=fopen("src.txt","r");
if(fp1==NULL) {
printf("open file failed\n");
}
FILE* fp2=fopen("des.txt","w");
if(fp2==NULL) {
printf("open file failed\n");
}
char buf[1024];
long pos;
while(fread(&buf,sizeof(buf),1,fp1)) {
pos=ftell(fp1);
fwrite(&buf,sizeof(buf),1,fp2);
}
if(feof(fp1)) {
fseek(fp1,pos,SEEK_SET);
char temp;
while(!feof(fp1)) {
fread(&temp,sizeof(char),1,fp1);
fwrite(&temp,sizeof(char),1,fp2);
}
}else {
printf("write file failed\n");
}
return 0;
}