user-0 提问: 急：c语言如何实现DOS命令:copy/B

回复:
user: user-1
content: 这样可好：  FILE *fs, *fd; char buf[256]; int n; int main(int argc, char *argv[]) { 	if (3 != argc) 	{ 		printf("usage:copy filesrc filedest\n"); 		return 1; 	} 	if (NULL == (fs = fopen(argv[1], "rb"))) 	{ 		fprintf(stderr, "can not open file %s\n", argv[1]); 		return 2; 	} 	if (NULL == (fd = fopen(argv[2], "wb"))) 	{ 		fprintf(stderr, "can not create file %s\n", argv[2]); 		fclose(fs); 		return 2; 	} 	while (1) 	{ 		if (0 == (n = fread(buf, 1, 256, fs))) break; 		fwrite(buf, 1, n, fd); 	} 	fcloseall(); 	return 0; }

user: user-2
content: 不要把 fopen("...","...");fscanf,fprintf,fgets,fgetc,fclose //读时把\r\n替换成\n，写时把\n替换成\r\n;读到\x1a就设置EOF;读写的内容当字符看待 和 fopen("...","...b");fseek,ftell,fread,fwrite,fgetc,fclose //不作以上替换，遇到\x1a仍继续读;读写的内容当字节看待 弄混了

user: user-3
content: FILE *fs, *fd; char buf[256]; int n; int main(int argc, char *argv[]) {     if (3 != argc)     {         printf("usage:copy filesrc filedest\n");         return 1;     }     if (NULL == (fs = fopen(argv[1], "rb")))     {         fprintf(stderr, "can not open file %s\n", argv[1]);         return 2;     }     if (NULL == (fd = fopen(argv[2], "wb")))     {         fprintf(stderr, "can not create file %s\n", argv[2]);         fclose(fs);         return 2;     }     while (1)     {         if (0 == (n = fread(buf, 1, 256, fs))) break;         fwrite(buf, 1, n, fd);     }     fcloseall();     return 0; }

user: user-0
content: 引用 5 楼 zhangxiangDavaid 的回复:[quote=引用 4 楼 lovecjyjack 的回复:] [quote=引用 1 楼 zhangxiangDavaid 的回复:] 这样可好：  FILE *fs, *fd; char buf[256]; int n; int main(int argc, char *argv[]) { 	if (3 != argc) 	{ 		printf("usage:copy filesrc filedest\n"); 		return 1; 	} 	if (NULL == (fs = fopen(argv[1], "rb"))) 	{ 		fprintf(stderr, "can not open file %s\n", argv[1]); 		return 2; 	} 	if (NULL == (fd = fopen(argv[2], "wb"))) 	{ 		fprintf(stderr, "can not create file %s\n", argv[2]); 		fclose(fs); 		return 2; 	} 	while (1) 	{ 		if (0 == (n = fread(buf, 1, 256, fs))) break; 		fwrite(buf, 1, n, fd); 	} 	fcloseall(); 	return 0; }   能具体一点吗？[/quote] 把该代码编译生成可执行程序，玩下，就知道了[/quote] 我能说直接输出usage:copy filesrc filedest吗。。。。。

user: user-1
content: 引用 4 楼 lovecjyjack 的回复:[quote=引用 1 楼 zhangxiangDavaid 的回复:] 这样可好：  FILE *fs, *fd; char buf[256]; int n; int main(int argc, char *argv[]) { 	if (3 != argc) 	{ 		printf("usage:copy filesrc filedest\n"); 		return 1; 	} 	if (NULL == (fs = fopen(argv[1], "rb"))) 	{ 		fprintf(stderr, "can not open file %s\n", argv[1]); 		return 2; 	} 	if (NULL == (fd = fopen(argv[2], "wb"))) 	{ 		fprintf(stderr, "can not create file %s\n", argv[2]); 		fclose(fs); 		return 2; 	} 	while (1) 	{ 		if (0 == (n = fread(buf, 1, 256, fs))) break; 		fwrite(buf, 1, n, fd); 	} 	fcloseall(); 	return 0; }   能具体一点吗？[/quote] 把该代码编译生成可执行程序，玩下，就知道了

user: user-0
content: 引用 1 楼 zhangxiangDavaid 的回复:这样可好：  FILE *fs, *fd; char buf[256]; int n; int main(int argc, char *argv[]) { 	if (3 != argc) 	{ 		printf("usage:copy filesrc filedest\n"); 		return 1; 	} 	if (NULL == (fs = fopen(argv[1], "rb"))) 	{ 		fprintf(stderr, "can not open file %s\n", argv[1]); 		return 2; 	} 	if (NULL == (fd = fopen(argv[2], "wb"))) 	{ 		fprintf(stderr, "can not create file %s\n", argv[2]); 		fclose(fs); 		return 2; 	} 	while (1) 	{ 		if (0 == (n = fread(buf, 1, 256, fs))) break; 		fwrite(buf, 1, n, fd); 	} 	fcloseall(); 	return 0; }   能具体一点吗？