faq: cached input with mygetch()
So I'm trying to put together a little text game at school on their redhat machines, right? I'm using a char buffer with system("clear") to write to the screen and mygetch() from the faq to get input.
Code:
int mygetch() {
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;
}
This function does what I need, except it waits for keyboard input before returning a value. Is there any way to get it to return like 0 or something when there's no input, or maybe a whole other function that does that?