Created
March 23, 2012 22:20
-
-
Save sinannar/2175646 to your computer and use it in GitHub Desktop.
Here is a function that implement in c,you can use it if you need a function that takes a character from user without enter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <termios.h> | |
#include <unistd.h> | |
char mygetch(void); | |
int main() | |
{ | |
/* | |
DRIVER SOURCE CODES HERE | |
I LEAVE IT AS SPACE | |
YOU CAN WRITE WHAT YOU WANT,YOU SHOULD TRY FIRST... | |
*/ | |
return 0; | |
} | |
char 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 (char)ch; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
awesome