I am not able to find equivalent header file for conio.h in Linux.
Is there any option for getch()
& getche()
function in Linux?
I want to make a switch case base menu where the user will give his option just by pressing one key & process should be moved ahead. I don't want to let user to press ENTER after pressing his choice.
You can use the
curses.h
library in linux as mentioned in the other answer.You can install it in Ubuntu by:
I took the installation part from here.
copy this function and use it, dont forget the includes
remove the last printf if you dont want the char to be displayed
There is a getch() function in the ncurses library. You can get it by installing the ncurses-dev package.
The replacement for
getch()
isgetchar()
declared instdio.h
.getchar()
is available on Windows and Linux.As said above
getch()
is in thencurses
library. ncurses has to be initialized, see i.e. getchar() returns the same value (27) for up and down arrow keys for thisI suggest you use curses.h or ncurses.h these implement keyboard management routines including getch(). You have several options to change the behavior of getch (i.e. wait for keypress or not).