C Programming: Getting Input Without Enter Key

  • Thread starter Thread starter Peter P.
  • Start date Start date
  • Tags Tags
    Input
Click For Summary

Discussion Overview

The discussion revolves around obtaining user input in C programming without requiring the Enter key to be pressed. Participants explore different libraries and functions that can facilitate this behavior, focusing on both standard and non-standard solutions.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant seeks functions that allow immediate input without pressing Enter, specifically asking about alternatives to scanf.
  • Another participant states that standard C does not support this functionality but suggests using system-dependent libraries like Curses, mentioning the function getch() as a potential solution.
  • A participant expresses interest in non-standard libraries, specifically conio.h, and questions whether to use it or Curses, seeking advice on setup for their specific compiler and operating system.
  • Further clarification is provided regarding the use of conio.h, indicating that it is suitable for programs intended to run in Windows DOS console mode or actual MSDOS environments.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach, as there are competing views regarding the use of conio.h versus Curses, and the discussion remains unresolved on which library is preferable.

Contextual Notes

Limitations include the dependency on operating system specifics and the potential issues with library initialization and termination, particularly with Curses.

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

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
6K
Replies
7
Views
2K
  • · Replies 20 ·
Replies
20
Views
2K
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 8 ·
Replies
8
Views
5K
Replies
14
Views
4K
Replies
19
Views
4K