Hey, I am supposed to write a simple shell for a programming class, but for some reason my parsing is messed up.
I am trying to use strtok to tokenize the input string into teh array tokArr, with the tokens being separated by a space in the input.
However, as my code is now, it only reads the first token, before getting out of the tokenizing while loop, then it reads the second token and prints it, etc for 2+tokens. Basically, only tokArr[0] is getting used.
Any help is appreciated,
Thanks
Code:
char *pt = NULL;
pt = strtok(input, " ");
//tokArr is an array of char*, each a token
char *tokArr[strlen(input)];
int i = 0;
while(pt != NULL){
printf("%s\n", pt);
tokArr[i] = pt;
pt = strtok(NULL, " ");
i++;
}