2012-06-09 22 views
0

,所以我有这样的代码目标C使用字符的字符串()

char processName[50] = {0};     // init all to 0 
printf("Enter the process to kill: "); 
scanf("%s", processName);     // read and format into the str buffer 
printf("Attempting to kill %s\n", processName); // print buffer 
system("killall %s", processName); 

把这个导致错误“太多的参数函数‘系统’”

回答

3

功能system只有一个参数,要执行的命令。您将不得不创建一个临时字符串来构建这样的命令。

char command[1024] = {}; 
sprintf(command, "killall %s", processName); 
system(command); 
+0

谢谢你,正是我一直在寻找 – xump