问题描述
- C语言,用命令行参数复制文件,请问哪里出错了
-
#include
#include
int main(int argc, char *argv[])
{
int ch;
errno_t err;
FILE *source, *destination;
if ((err = fopen_s(&source, argv[1], "rb") )!=0)
{
printf("can't open %sn", argv[1]);
exit(1);
}
if ((err = fopen_s(&destination, argv[2], "wb")) != 0)
{
printf("can't open %s n", argv[2]);
exit(1);
}
while ((ch = getc(source)) != EOF)
putc(ch, destination);
fclose(source);
fclose(destination);
printf("copy finishedn");
return 0;
}
解决方案
while ((ch = fgetc(source)) != EOF)//修改为fgetc
fputc(ch, destination); //修改为fputc
时间: 2024-10-22 22:11:02