我有这段代码;当您直接将参数写入 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/