Skip to content

Instantly share code, notes, and snippets.

@mhashim6
Created April 18, 2019 17:12
Show Gist options
  • Save mhashim6/7c21f8338f43a7e1ca36da4459661605 to your computer and use it in GitHub Desktop.
Save mhashim6/7c21f8338f43a7e1ca36da4459661605 to your computer and use it in GitHub Desktop.
#include <fcntl.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/termios.h>
#include <sys/time.h>
#include <sys/types.h>
struct termios original_tio;
void disable_input_buffering() {
tcgetattr(STDIN_FILENO, &original_tio);
struct termios new_tio = original_tio;
new_tio.c_lflag &= ~ICANON & ~ECHO;
tcsetattr(STDIN_FILENO, TCSANOW, &new_tio);
}
void restore_input_buffering() {
tcsetattr(STDIN_FILENO, TCSANOW, &original_tio);
}
int main() {
disable_input_buffering();
char c = getc(stdin);
printf("%c\n", c);
restore_input_buffering();
c = getc(stdin);
printf("%c\n", c);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment