编写一个文件复制程序。程序需要从命令行获得源文件名和目的文件名。尽可能使用标准I/O和二进制模式。
#include<stdio.h> #include<stdlib.h> int main(int argc,char *argv[]) { int ch; FILE *source,*destination; if ( (source = fopen(argv[1],"rb")) == NULL) { printf ("Can't open %s\n", argv[1]); exit(1); } if ( (destination = fopen(argv[2],"wb")) == NULL) { 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; }
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题