I know how scanf could be used for parsing sentences into single words:
while(1){
scanf("%s", buffer)
...
}
However, if I enter a sentence like one two three<return>, how can I find out inside a while-loop if the word I’m getting in the buffer is the one before I pressed <return>?
I guess it is hardly possible with scanf, but maybe there is a similar function?
You should use
fgets()to read the whole line, and parse it like so:Checking if the current word is the last word is trivial: