C Programming: Getting Input Without Enter Key

  • Thread starter Thread starter Peter P.
  • Start date Start date
  • Tags Tags
    Input
AI Thread Summary
The discussion centers on the need for functions in C programming that allow user input without requiring the Enter key, specifically through the use of libraries. Standard C does not support this functionality, but system-dependent libraries like Curses can be utilized. The getch() function from Curses allows for immediate input detection. However, proper initialization and termination of the library are crucial to avoid issues with keyboard input after program termination. Users also consider the conio.h library, which is suitable for Windows DOS console applications. For those using the Pelles C compiler on Windows 7, conio.h may be sufficient if the programs are intended for that environment, while Curses offers more flexibility for cross-platform applications. Guidance on setting up Curses is requested, indicating a need for clear instructions for users unfamiliar with the library.
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
What percentage of programmers have learned to touch type? Have you? Do you think it's important, not just for programming, but for more-than-casual computer users generally? ChatGPT didn't have much on it ("Research indicates that less than 20% of people can touch type fluently, with many relying on the hunt-and-peck method for typing ."). 'Hunt-and-peck method' made me smile. It added, "For programmers, touch typing is a valuable skill that can enhance speed, accuracy, and focus. While...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top