Why is it that sometimes, my program does not ask the user for input even if I have used gets();
Thanks, Shilpi
Printable View
Why is it that sometimes, my program does not ask the user for input even if I have used gets();
Thanks, Shilpi
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.
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
Try removing the \n from the previous statement and see how it goes, but I don't think that's the problem.
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...