Click to See Complete Forum and Search --> : gets() input statement


shilpichaudhry
December 10th, 2002, 08:12 PM
Why is it that sometimes, my program does not ask the user for input even if I have used gets();
Thanks, Shilpi

Elrond
December 11th, 2002, 03:22 AM
If I remember well, gets returns when the user presses the 'Enter' key.

If for whatever reason, the user double-presses this key at the end of the previous thing he was doing, then gets might return with an empty string, and that look as if nothing was asked to the user.

shilpichaudhry
December 11th, 2002, 09:24 AM
Nope I didn't press the enter key twice in any of the previous queries, but do you think having a cprintf statment or cout statement with "\n" before gets would matter?
Shilpi

Elrond
December 11th, 2002, 09:30 AM
Try removing the \n from the previous statement and see how it goes, but I don't think that's the problem.

ashishd
December 11th, 2002, 11:23 PM
I also faced the same problem sometime back...If I remember it correctly then I used flush() before making a call to gets so that the buffer will be empty and that worked in my case.

U can also try the same...