题目:
用fgetc和fputc实现一个文件的拷贝,例如将a.c中的内容拷贝到b.c中
拷贝完毕后 可以用diff指令判断 两个文件是否相同: diff a.c b.c。
程序:
#include <stdio.h>
#include<string.h>
int main(int argc, const char *argv[])
{
//打开a.c文件
FILE *fp=fopen("./a.c","r");
if(NULL==fp)
{
perror("fopen");
return -1;
}
FILE *fp1=fopen("./b.c","w");
if(NULL==fp1)
{
perror("fopen");
return -1;
}
while(1)
{
int c=fgetc(fp);
if(EOF==c)
{
break;
}
else
{
fputc(c,fp1);
}
}
fclose(fp);
fclose(fp1);
return 0;
}
运行结果: