Skip to content

Instantly share code, notes, and snippets.

@sinannar
Created March 23, 2012 22:20
Show Gist options
  • Save sinannar/2175646 to your computer and use it in GitHub Desktop.
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
#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;
}
@orazdow
Copy link

orazdow commented Feb 26, 2018

awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment