Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C - getting input

  1. Dec 29, 2011 #1
    im looking for functions that do not require the user to press enter. such as, they press "a" and the program continues, instead of something like "a[enter]" when using scanf.
     
  2. jcsd
  3. Dec 29, 2011 #2

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

    You can't do this in standard C.

    You can do it using system-dependent libraries. One that is fairly widely available (but with minor differences on different operating systems) is http://en.wikipedia.org/wiki/Curses_(programming_library [Broken]). The function you want is getch(), but you need to read a tutorial to find out how to initialize and terminate using the library properly. (Otherwise, in the worst case, when your program terminates NOTHING will be able to read the keyboard again until you reboot the computer!)
     
    Last edited by a moderator: May 5, 2017
  4. Dec 29, 2011 #3
    Thanks for the reply.

    Also, i was looking through the non-standard libraries that the compiler i use has, and noticed conio.h, i was wondering whether it would be better to just stick with conio or use curses? and if anyone would suggest curses, can you possibly tell me how to set it up? i use pelles c compiler and my laptop is running windows 7.
     
    Last edited: Dec 30, 2011
  5. Dec 30, 2011 #4

    rcgldr

    User Avatar
    Homework Helper

    If you only plan to run those programs in windows dos console mode (or an actual copy of MSDOS, either dual boot or virtual pc), then conio is fine.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: C - getting input
  1. Taking inputs in C (Replies: 11)

Loading...