我正在编写一个命令行实用程序,但我找不到存储命令和参数的方法。到目前为止,我有以下内容,但出现分段错误:
int main(void)
{
char *command;
char *args[MAX_LINE/2 + 1];
int should_run = 1;
do{
cout << "cmd> ";
int counter = 0;
while(cin >> command) {
strcpy(args[counter],command);
counter++;
}
cout << args[0] << "\n";
}
}