Saturday, 18 June 2011

getch() not found on linux conio.h

conio.h getch() is not standard C and is sepcific to DOS, todo it on linux do:-

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

int getch( ) {
  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;
}

No comments:

Post a Comment