I am writing a program for a school project that should emulate a Unix shell in a very simple way. It basically parses the input, and then does fork / exec. I need to be able to read the arguments in the program (and not as the arguments passed to the program from the command line) separately. For example, I will prompt:
Please enter a command:
... and I need to make out both ...
ls
OR
ls -l
but the problem is that there seems to be no easy way to do this. scanf()will pull each argument individually, but I don’t see the possibility of placing them in different slots in the char * array. For example, if I ...
char * user_input[10];
for (int i=0; i<10; i++){
user_input[i] = (char *) malloc(100*sizeof(char));
}
for (int i=0; *(user_input[i]) != '@'; i++)
{
scanf("%s", user_input[index]);
index++;
}
... then it user_input[0]will receive "ls", then the cycle will begin, then it user_input[0]will receive "-l".
gets fgets . , , ... , , . ?
!