C Programming: Getting Input Without Enter Key

  • Thread starter Thread starter Peter P.
  • Start date Start date
  • Tags Tags
    Input
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 3K views
Peter P.
Messages
23
Reaction score
0
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.
 
Physics news on Phys.org
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 ). 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:
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:
Peter P. said:
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?
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.