So, I'm trying to write an ac program that reads the input into the program (via stdin), but I also need to be able to read input from the terminal (so I obviously can't read it from stdin), How do I do this? I am trying to open another file descriptor for / dev / tty as follows:
int see_more() { char response; int rd = open("/dev/tty", O_RDWR); FILE* reader = fdopen(rd, "r"); while ((response = getc(reader)) != EOF) { switch (response) { case 'q': return 0; case ' ': return 1; case '\n': return -1; } } }
But this leads to a segmentation error.
Here is the version that works. Thanks for helping everyone :)
int see_more() { char response; while (read(2, &response, 1)) { switch (response) { case 'q': return 0; case ' ': return 1; case '\n': return -1; } } }
David source share