Getch() for linux

  • Thread starter i.mehrzad
  • Start date
  • #1
84
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.
 

Answers and Replies

  • #2
mgb_phys
Science Advisor
Homework Helper
7,774
13
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
 
  • #3
84
0
Can you please repeat the name of the book. I mean i don't know the acronym
 
  • #4
mgb_phys
Science Advisor
Homework Helper
7,774
13
http://en.wikipedia.org/wiki/The_C_Programming_Language_(book [Broken])
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:
  • #5
jim mcnamara
Mentor
4,106
2,607
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.
 

Related Threads on Getch() for linux

Replies
1
Views
4K
  • Last Post
Replies
3
Views
3K
  • Last Post
Replies
3
Views
3K
  • Last Post
Replies
9
Views
1K
  • Last Post
Replies
1
Views
8K
  • Last Post
2
Replies
38
Views
2K
Replies
2
Views
2K
Replies
4
Views
2K
Replies
1
Views
3K
  • Last Post
Replies
6
Views
2K
Top