Lets say I have a buffer and some other pointer for storing the stdin:
char buffer[256];
char *command[3];
And I'm reading from stdin into buffer:
fgets(buffer, BUF_SIZE, stdin);
If stdin was ls -s1
, I want to have command[0]="ls"
and command[1]="-s1"
. I also want command[2]=NULL
.
For context I am trying to use execvp()
later on so I want all the commands separated in command
with the null character at the end.
Could someone please let me know how could I go about saving the commands in the command array in that order?