Click to See Complete Forum and Search --> : correction


Hyena
October 18th, 1999, 07:28 AM
whoops, i made a mistake in the other post- its not that char ans generates an error, its just that it doesnt work in the loop. its supposed to quit when ans doesnt equal y, but even when i specifically type in 'n' the loop doesnt stop.

Wayne Fuller
October 18th, 1999, 07:52 AM
Make sure you flush the keyboard first, otherwise you may be getting some characters that you do not want.

Hyena
October 18th, 1999, 09:38 AM
'flush the keyboard'? what is that, how do you do it?

Wayne Fuller
October 18th, 1999, 09:43 AM
There is a C call, fflush(FILE *) that you can use.

fflush(stdin);

Or just use your own.

while ( getchar() != '\n' );

By doing what you are doing, you are assuming that the keyboard buffer is empty. And many times it is not.

Just call one of these routines before you try to get any keyboard data.