So my shell project has been coming along, but my latest speedbump is introducing user input. I'm trying to tokenize an input string, but after the first token strtok
only returns NULL. But if I hard-write the string in the program, everything works flawlessly. How I can I treat the user input so that strtok
will tokenize the whole string (instead of the first)?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char input[100];
scanf("%s", input); //input entered is "echo 1 2 3 4"
char *temp=strtok(input, " "); //this is "echo"
printf("temp1: %s\n", temp);
temp=strtok(NULL, " "); //this is (null)
printf("temp2: %s\n", temp);
}