2012-06-09 21 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