#include "stdio.h"
#include "stdlib.h"
int main()
{
FILE *f1,*f2;
char c;
if ((f1=fopen("f1.dat","r"))==NULL)
{
printf("文件打开失败");
exit(0);
}
if ((f2=fopen("f2.dat","w"))==NULL)
{
printf("文件打开失败");
exit(0);
}
c = fgetc(f1);
while (c!=EOF)
{
fputc(c,f2);
c = fgetc(f1);
}
fclose(f1);
fclose(f2);
return 0;
}
结果:把f1文件里的内容复制到f2文件中
心得:连续几次都在开文件的时候出错,一定要把文件名写对!