Objective C在system()中使用char字符串

时间:2012-06-09 20:54:41

标签: objective-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);

这会导致错误“函数'系统'的参数太多”

1 个答案:

答案 0 :(得分:3)

函数system只接受一个参数,即执行命令。您必须创建一个临时字符串来构建此类命令。

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