本段代码实现了将一个文件内容复制到另外一个文件中的功能
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
FILE *fp1,*fp2;
if((fp1=fopen("file1.c","r"))==NULL)
{
printf("cannot open file1\n");
exit(0);
}
if((fp2=fopen("file2.c","w"))==NULL)
{
printf("cannot open file2\n");
exit(0);
}
while(!feof(fp1))
putchar(getc(fp1));
rewind(fp1);/*将文件1的指针重新定位到文件的开头处*/
while(!feof(fp1))
putc(getc(fp1),fp2);
fclose(fp1);
fclose(fp2);
printf("copy compony\n");
return 0;
}