#include<stdio.h>
/* fgetc读取一次读取一个字符 */
/* int fgetc(FILE *stream); */
int main(int argc,char *argv[])
{
if (argc < 3)
{
fprintf(stderr, "usage:%s filename1, filename2\n", argv[0]);
return -1;
}
FILE *fd1 = fopen(argv[1], "r");
if (NULL == fd1)
{
perror("fopen");
return -1;
}
int ret;
FILE *fd2 = fopen(argv[2],"w");
if (NULL == fd2)
{
perror("fopen");
return -1;
}
while(1)
{
ret = fgetc(fd1);
if (EOF == ret)
{
printf("read file end\n");
break;
}
if (EOF == fputc(ret, fd2))
{
printf("write file enf\n");
break;
}
}
return 0;
}
fgetc和fputc实现文件拷贝
最新推荐文章于 2023-09-24 22:54:00 发布