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

enum { bufsize = 128 };

int main()
{
    struct termios ts1, ts2;
    char buf[bufsize];
    char *r;

    if (!isatty(0)) {
        fprintf(stderr, "Not a terminal, sorry\n");
        return 1;
    }

    tcgetattr(0, &ts1);
    memcpy(&ts2, &ts1, sizeof(ts1));
    ts1.c_lflag &= ~ECHO;
    tcsetattr(0, TCSANOW, &ts1);
    printf("Please bind-type the code: ");
    r = fgets(buf, sizeof(buf), stdin);
    if (!r) {
        fprintf(stderr, "Unexpected end of file\n");
        return 1;
    }
    printf("\nThe code you entered is [%s]\n", buf);
    tcsetattr(0, TCSANOW, &ts2);
    return 0;
}
