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.
Printable View
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.
Make sure you flush the keyboard first, otherwise you may be getting some characters that you do not want.
'flush the keyboard'? what is that, how do you do it?
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.