Extract inputs from a pointer to array of characters in C / C++
Posted
by
user2066884
on Stack Overflow
See other posts from Stack Overflow
or by user2066884
Published on 2013-10-20T21:50:00Z
Indexed on
2013/10/20
21:53 UTC
Read the original article
Hit count: 120
I am writing a command line utility but I cannot find a way to store the commands and arguments. so far I have the following but I get a Segmentation fault:
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";
}
}
© Stack Overflow or respective owner