Finding a Substitute for getch() on Linux | C Programming & Linux

  • Thread starter Thread starter i.mehrzad
  • Start date Start date
  • Tags Tags
    Linux
AI Thread Summary
The discussion centers around finding a substitute for the getch() function, which is not available on Linux as it is a DOS-based command. Users are seeking a way to capture input without displaying it on the screen. While getpass() was mentioned, it was noted that it may not function correctly for this purpose. The conversation highlights that getchar() can be used, but to read input character by character without waiting for the Enter key, the terminal must be set to non-canonical mode using the termios library. This involves configuring the terminal settings to read keystrokes directly and then resetting them afterward. The discussion also references "The C Programming Language" by Kernighan and Ritchie (K&R) as a valuable resource for learning C, particularly in a Unix/Linux context. It is emphasized that the approach to handling input is OS-dependent, with Windows having its own equivalent functions.
i.mehrzad
Messages
84
Reaction score
0
I use the linux operating system. And at present programming in C.
The getch() doesn't seem to exist on Linux. I know that it is a DOS based command. What is the substitute for getch() on Linux.


I mean is there any command out there which can take my input without displaying the output. I tried the getpass() command but it doesn't work fine

Can someone please help.
 
Technology news on Phys.org
getchar(), although if you need each character at a time without waiting for the enter key you might have to set the terminal mode.
Remember unix is written in C and C was invented for unix so any good C book (such as K&R) will apply directly to unix/linux
 
Can you please repeat the name of the book. I mean i don't know the acronym
 
http://en.wikipedia.org/wiki/The_C_Programming_Language_(book )
It isn't the easiest intro to programming book, but if you have a background it is a good way to learn C.
 
Last edited by a moderator:
I don't have my example at hand. You have to use termios to set the terminal (tty) to non-canonical mode, read a keystroke, then reset the tty to canonical mode.

In other words it is OS dependent - the example I gave was unix-based. Windows has a call - _getche() as I remember. You can set the tty mode in windows as well.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top