Michael Goerz wrote:
>
why does the following result in an infinite loop when the user
does *not* enter a number?
do{
printf("Enter Number: ");
} while ( ! scanf("%i", &input) );
Because nothing flushes the input data that does not form a
number. If something beginning with 'z', for example, does not
form a number, it still doesn't form a number on rescan.
Don't use scanf for interactive input. It bites.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>