HI.
There are a number of issues at work in your little proggy. But first, a couple of things to know:
1. scanf will not skip leading whitespace when used with scanners;
2. scanf will probably leave the output string unchanged if it fails (failure should be determined from the returned int);
3. Subsequent scanf reads will read and match from where the last scanf stopped matching.
Knowing the above, this is what I think happened:
- first time in the loop, scanf reads whatever you give it until new line;
- subsequent scanf read and attempt to match from new line and fail (the string is preserved, however);
- so on until the end.
In an an attempt to fix this, you'll want to get rid of all chars not matched (new line, in your case) by, say, adding to the format specifier. I say attempt, because this can still fail in so many other ways...
Arthur