"[code:c]"
#include <stdio.h>
int main(int argc, char const *argv[])
{
FILE *fp_src, *fp_dest;
char buf[32] = "";
if (argc != 3)
{
printf("format: %s <srcfile> <destfile>\n", argv[0]);
return -1;
}
//打开文件
fp_src = fopen(argv[1], "r");
if (NULL == fp_src)
{
perror("open src file err");
return -1;
}
fp_dest = fopen(argv[2], "w");
if (NULL == fp_dest)
{
perror("open dest file err");
return -1;
}
//循环读源文件,读到就写入目标文件
while (fgets(buf, 32, fp_src) != NULL)
{
fputs(buf, fp_dest);
}
fclose(fp_dest);
fclose(fp_src);
return 0;
}
c语言——用标准IO实现cp功能
最新推荐文章于 2024-07-18 14:11:06 发布