Thread: In C preventing the user from hitting enter after an input

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    3

    In C preventing the user from hitting enter after an input

    I am sorry if this was already answered. Can someone tell me how, in C, the program moves on after the user enters 1 keystroke.

    The user has to choose a 1 through 5. I would like to have the program go on after they input their selection. Currently they have to hit enter.

    Thanks for the help

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Is this what you were looking for?

    ~/

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    3
    That did not solve the problem. I may be using it incorrectly. Does this go with scanf?
    Thanks

  4. #4
    ---
    Join Date
    May 2004
    Posts
    1,379
    Quote Originally Posted by From the above link
    Using standard C/C++, you cannot. However, if you're lucky your compiler may have the non-standard conio.h header (which might include getch()), if you're on *nix (UNIX, Linux, etc.) you can try the ncurses library or switching the terminal mode. On Windows, try the different API input routines (such as those included in the Win32 API).
    Summary
    • Can't do it in standard C/C++
    • Can use getch() from conio.h (non standard)
    • Can use the portable ncurses library
    • Can use the Windows API

  5. #5
    n00b
    Join Date
    May 2005
    Location
    Lakefield
    Posts
    12
    What about?
    Code:
    getchar()

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    getchar() waits for the user to press enter.

    [edit]
    And then it retrieves only one char from the input stream. But on the other hand, it is an ANSI function.
    [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  2. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  3. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  4. ~ User Input script help~
    By indy in forum C Programming
    Replies: 4
    Last Post: 12-02-2003, 06:01 AM
  5. Getting input without the user having to press Enter...
    By Ranedhel in forum C++ Programming
    Replies: 18
    Last Post: 07-16-2003, 05:36 PM