CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2002
    Posts
    96

    gets() input statement

    Why is it that sometimes, my program does not ask the user for input even if I have used gets();
    Thanks, Shilpi

  2. #2
    Join Date
    Oct 2001
    Location
    Dublin, Eire
    Posts
    880
    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.
    Elrond
    A chess genius is a human being who focuses vast, little-understood mental gifts and labors on an ultimately trivial human enterprise.
    -- George Steiner

  3. #3
    Join Date
    Mar 2002
    Posts
    96
    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

  4. #4
    Join Date
    Oct 2001
    Location
    Dublin, Eire
    Posts
    880
    Try removing the \n from the previous statement and see how it goes, but I don't think that's the problem.
    Elrond
    A chess genius is a human being who focuses vast, little-understood mental gifts and labors on an ultimately trivial human enterprise.
    -- George Steiner

  5. #5
    Join Date
    Aug 1999
    Location
    India
    Posts
    15

    Lightbulb

    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured