Hi everyone, I'm currently working on a project in which I have to write a basic UNIX shell. My problem is with parsing the command line. I am using strtok to retrieve the first command (the program to be run) and putting it in a struct. I am having a problem with getting the argument values into an array of strings. I am trying to use strtok to get the args one by one, and then strcpy to put them into the array. I keep getting seg faults when I try to do this. Here is the relevant portions of the code:
struct command_t *command;
cout << "$$ ";
fgets(in, 100, stdin);
str = strtok(in, " ");
command->name = str;
str = strtok(NULL, " ");
Using the debugger, I find the seg fault occurs right at the strcpy command. Any suggestions?
Cool, thanks a lot, that seems to work a lot better. Now, how could I allocate memory for all of the argv vectors(i.e. argv, argv, etc...), without using a loop if possible?