新手又来求助,老师们请进!
功能是把一个文件的内容复制到另一个文件。我知道有简便的方法,这个是我自己写的笨方法,可是复制结果总是不正确,请老师们看看错在哪里了!
#include<stdio.h>c
#include<stdlib.h>
main()
{
FILE *p1,*p2;
char fuzhi[40];
int i=0;
if((p1=fopen("lianxi.txt","r"))==NULL){
printf("can not open file\n");
exit(1);
}
while(fgetc(p1)!=EOF){
fuzhi[i]=fgetc(p1);
i++;
}
fuzhi[i]='\0';
fclose(p1);
if((p2=fopen("xiao.txt","w"))==NULL){
printf("can not open file\n");
exit(1);
}
i=0;
while(fuzhi[i]!='\0'){
fputc(fuzhi[i],p2);
i++;
}
fclose(p2);
}
int ch;
...
while((ch = fgetc(p1))!=EOF){
fuzhi[i]=ch;
i++;
}