I am trying to get all the input from the command line and putting it in a linked list.
the numbers from the command line are of this format 0-1 2-3 4-9 etcc
Here is what I did to store a pair of numbers in two variables:
scanf("%d-%d", &a, &b);
Now, this scanf statement is inside a loop and my question is: what is the condition of the loop?
I want to keep doing scanf until all the input is finished.
Thanks in advance.
A famous, if not notorious characteristic of
scanfis that it will leave data in input buffer when reading non-string data(e.g,int). Check out here: Leave data in input buffer.Try this:
You need to compare
scanfoutput with EOF. And most importantly, you need flush out the'\n'left byscanfin input buffer.