#include <sys/types.h>

#include <stdio.h>
#include <termios.h>
#include <unistd.h>

static struct termios orig;
static struct termios raw;
static char buf[8];

int main(void) {
    printf("Each keypress is echoed as 'c'. Press 'q' to quit.\n");
    tcgetattr(STDIN_FILENO, &orig);
    cfmakeraw(&raw);
    tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
    do {
        read(STDIN_FILENO, buf, sizeof(buf));
        printf("c");
        fflush(stdout);
    } while (buf[0] != 'q');
    tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig);
    printf("\n");
    return 0;
}