I have a string input which contains words separated by white-space. I want to use sscanf() to split the words, store each word in input_word and print it, but I’m not sure how to put it in a while loop.
This is what I have:
char input[max];
char split_input[max];
/* input gets populated here */
while (sscanf(input," %s", split_input)) {
printf("[%s]\n", split_input);
}
What would be the condition to terminate the loop as soon as the last word in the sequence is split?
you’re using the wrong function there. Might I suggest
strtok()instead?Read here for strtok