#include <stdio.h>
int main(int argc, const char *argv[])
{
//用fgetc()将01.c文件中的内空写入到02.c文件中去
FILE *fp1 = fopen("./01.c","r"); //用-r读方式打开文件01.c
if (NULL == fp1)
{
perror("fopen");
return -1;
}
FILE *fp2 = fopen("./02.c","w"); //用-w写方式打开文件02.c
if (NULL == fp2)
{
perror("fopen");
return -1;
}
char c; //定义一个字符变量接收
while ((c=fgetc(fp1)) != EOF)
{
fputc(c,fp2); //将字符c写入文件02.c中
}
printf("文件拷贝完毕\n");
fclose(fp1);
fclose(fp2);
return 0;
}