42 lines
820 B
C
42 lines
820 B
C
#include <stdio.h>
|
|
#include <termios.h>
|
|
#include <unistd.h>
|
|
|
|
int main()
|
|
{
|
|
int c;
|
|
int flag = 0;
|
|
|
|
/*
|
|
THIS IS A REPLACEMENT FOR THE _KBHIT FUNCTION
|
|
*/
|
|
|
|
// These structs are for saving tty parameters
|
|
static struct termios old_term, new_term;
|
|
|
|
// Get parameters associated with the tty
|
|
// Set the new tty parameters to the old one
|
|
tcgetattr(STDIN_FILENO, &old_term);
|
|
new_term = old_term;
|
|
|
|
// Set the new tty parameters to canonical mode
|
|
new_term.c_lflag &= ~(ICANON);
|
|
|
|
// Set tty attributes
|
|
tcsetattr(STDIN_FILENO, TCSANOW, &new_term);
|
|
|
|
// Get character input by user
|
|
while ((c = getchar()) != EOF)
|
|
{
|
|
flag = !flag;
|
|
printf("\n");
|
|
printf("Flag: %d\n", flag);
|
|
}
|
|
|
|
// Done retriving input
|
|
// Set tty parameters back to old tty parameters
|
|
tcsetattr(STDIN_FILENO, TCSANOW, &old_term);
|
|
|
|
return 0;
|
|
}
|