C++ system函数中能否有变量?

来源:百度知道 编辑:UC知道 时间:2024/09/22 01:07:37
例如copy 一个文件,而这个文件名又是变量,该怎么办?

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
main()
{
char file1[15];
char file2[16]=" ";//一个空格
char copycmd[50]="copy ";
printf("input first name\n");
scanf("%s",file1);
printf("input first name\n");
scanf("%s",file2+1);
strcat(copycmd,file1);
strcat(copycmd,file2);
printf("%s\n",copycmd);
system(copycmd);
}

把两个字符串连接成一个字符串
得到的字符串当作system()的参数
然后就可以了

?问题是很明了.