Quote:
> I'm having a problem with the scanf function. In my program I
> have the following bit of code:
> int result;
> scanf("%d", &result);
> It works fine as long as the user types a series of digit keys (0-9).
> However, if the user types an alpha key, the whole thing goes crazy.
> The program goes into an infinite loop and repeatedly blows right
> through scanf.
Use fgets() to get a line of input (using stdin for the stream argument, and
please don't use gets() instead of fgets()... ), and then go through it using
sscanf(), or such functions as strtol(). The man page or your compiler's manual
will give you all the details.
--
^^
University of Twente =x= \ tel. +31 53 893747
Tele-Informatics & Open Systems | \ tfx. +31 53 333815
P.O. Box 217 7500 AE Enschede /|__ \
The Netherlands (____)_/
"Spare no expense to save money on this one."
-- Samuel Goldwyn