In response to a question on Quora, I offered the following code example that turns off terminal buffering on both Windows and Linux:
#include <stdio.h>
#ifdef _WIN32
#include <windows.h>
#else
#include <termios.h>
#include <sys/ioctl.h>
#endif
int main()
{
int c;
#ifdef WIN32
HANDLE hCon;
DWORD dwMode;
hCon = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode(hCon, &dwMode);
SetConsoleMode(hCon, dwMode & !ENABLE_LINE_INPUT);
#else
struct termios ts;
ioctl(0, TCGETS, &ts);
ts.c_lflag &= !ICANON;
ioctl(0, TCSETS, &ts);
#endif
c = getchar();
while (c != EOF)
{
printf("getchar received %c\n", c);
c = getchar();
}
}
