Connect with Expertise | Find Experts, Get Answers, Share Insights

Getch() in Linux

 
Join Date: Jun 2006
Posts: 2
#1: Jun 21 '06
Does anyone know of a getch() equivalent that exists in linux?
I have just started doing some basic programming and am currently running Knoppix on CD.
So I'm not sure what kind of file library I have available.

Any help would be greatly appreciated;

GL

Banfa's Avatar
E
M
C
 
Join Date: Feb 2006
Location: South West UK
Posts: 7,156
#2: Jun 21 '06

re: Getch() in Linux


What programming language are you talking about? C/C++?

In my MSVC I can find

getc
getchar
_getch

getc and getch are standard library functions and should be found in any C/C++ implementation.

_getch is a platform implementation function (denoted by the _ at the start of the name), a function provide by the platform in question to support the rest of the c standard library.

The closest standard library equivilent to _getch is getchar.
 
Join Date: Oct 2008
Posts: 1
#3: Oct 1 '08

re: Getch() in Linux


What programming language are you talking about? C/C++?

In my MSVC I can find

getc
getchar
_getch

getc and getch are standard library functions and should be found in any C/C++ implementation.

_getch is a platform implementation function (denoted by the _ at the start of the name), a function provide by the platform in question to support the rest of the c standard library.

The closest standard library equivilent to _getch is getchar.

Put the following text in to Gedit and save as getch.h
to use the function use mygetch()

works like a charm

/

#include <termios.h>
#include <unistd.h>

int mygetch(void)
{
struct termios oldt,
newt;
int ch;
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newt );
ch = getchar();
tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
return ch;
}


/solution provided by kermi3 from this web posting http://cboard.cprogramming.com/archive/index.php/t-27714.html
Reply

Tags
getch lib