
newbie problem with scanf
Quote:
> while (scanf("%d", &next)!= EOF) {
You're testing the result of scanf() incorrectly. scanf() returns the
number of things it managed to match in the format string, so in this
case you want to say:
while (scanf("%d", &next) == 1) {
which will run while scanf() manages to read a value in. The program
will stop if a letter is typed, or it hits EOF.
Quote:
> if (next > latest) {
> largest = next;
> latest = next;
largest and latest will pretty much always have the same value during
your program. This doesn't stop it working, but it does suggest
something you might want to do.
Quote:
> next = 0; }
You don't need to reset the value of next - scanf() doesn't care what
it is, it will just overwrite it.
Quote:
> }
--
http://www.tardis.ed.ac.uk/~broonie/
EUFS http://www.ed.ac.uk/~filmsoc/