C 在 Windows 上,复制文件的代码不起作用

标签 c windows copy cmd

我有这段代码;当您直接将参数写入 system() 时它会起作用,如果您将参数传递给它则不起作用。有什么帮助吗?

char dest[100];
char file[50];
char dir[100];

printf("Enter source path: ");
scanf("%s", dir);

printf("Enter filename: ");
scanf("%s", file);

printf("Enter destination path: ");
scanf("%s", dest);

system("move \"c:\\users\\putty.exe\" g:\\ \n" );  /* <--works        */
system("move \"%s%s\" %s", dir,file,dest);         /* <--doesn't work */

最佳答案

你可以试试这个

char dest[100];
char file[50];
char dir[100];
char command[300];
printf("Enter source path: ");
scanf("%s", dir);
printf("Enter filename: ");
scanf("%s", file);
printf("Enter destination path: ");
scanf("%s", dest);
sprintf(command,"move %s%s %s", dir,file,dest);  
system(command); 

关于C 在 Windows 上,复制文件的代码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14472389/

相关文章:

c - VkApplicationInfo 有什么意义?

windows - OpenSSL 在 PKCS12 导出期间挂起, "Loading ' 屏幕'进入随机状态“

c++ - Qt:如何设置主窗口的初始位置?

c++ - 使用 `std::copy()` 和 `std::back_inserter()`

c - 1 除以非常大的数返回 0, C

c - C 中的输入字符串数组内存管理

c - 提高在 C 中合并两个文件的 IO 性能

windows - 为什么 OSQuery 在读取 Windows EventLogs 时不包含 "Computer"事件信息?

java - Java中可以使用bufferedreader来复制arxml文件吗?

java - 如何复制(而不是引用)二维字符串?