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 %s\n", 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 finished\n");
return 0;
}

1个回答

    while ((ch = fgetc(source)) != EOF)//修改为fgetc
        fputc(ch, destination); //修改为fputc

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问