B
Ben Bacarisse
Bill Cunningham said:I mean 1 not zero. I guess zero would be no input.
int c;
c=fscanf...
while(c!=0)...loop
Would that be a correct statement for this or maybe,
while(c!=0||c!=EOF){}
No. That test is always true so it can't ever be what you want in such
a loop. If you can't see why it's always true I fear that programming
may not be for you. (Of course it might just have been at typo -- I
make loads of those.)
I gave you some sounds advice about scanf. Here it is again: all scanf
loops should be written with the test for what you want to get, not for
the negation of what you don't want.
If you want one item you write
while (scanf(...) == 1) ...
If the format is designed to read two items:
while (scanf(...) == 2) ...
Sometimes what you want is more subtle. You may want at least one
number, so you'd write:
while (scanf(...) >= 1) ...
This way you know that you will only process correct data, and that the
loop will stop when anything goes wrong. scanf can fail for all sorts
of reasons and it's fiddly to invert the test correctly, so don't try.