getche() on linux

I can use getche() function on windows borland but I cant use getche() on linux.İs there any alternative this functions on linux?? Please help I look all internet sites and I cant find any alternative
Use curses library if are using Linux, it provides this function.
I still see this error message ..
fatal error: ncurses.h: No such file or directory
compilation terminated.
Did you actually install ncurses, or did you just expect it would work?
@link provided by kbw - please enclose non-standard platform specifics with preprocessor conditionals. Otherwise non-posix systems will encounter obscure compile-time errors. It's always good practice to protect your translation units from non-standard elements like shown below. I realize this is the UNIX section, but there is absolutely no reason to make this function platform-dependent given how easy it is to make a cross-platform, modular solution of it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#ifndef GETCH_1_23_2014_HPP
#	define GETCH_1_23_2014_HPP
#	if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
#		include <termios.h>
#		include <unistd.h>
int getch(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;
}
#	elif defined(_WIN32)
#		include <conio.h>
#	else
#		error getch is not available on the target system
#	endif
#endif //GETCH_1_23_2014_HPP 
Last edited on
These codes working %100. Thank you a lot :D
Topic archived. No new replies allowed.