On Terminal in my ubuntu, to exit a 'man page view' (manual) of any utility, I just need to click 'q' on keyboard and it instantly exits.
I have a simple Binary reader program (displays byte-wise value, both hexadecimal and printable ASCII character, similar to hexdump) written in C. I programmed it to display 8 Bytes on one line, and next 8 in the successive line.
Ideally my program need to print next line every time I press "ENTER" and it should stop displaying (process should exit/return) immediately after pressing 'q' on keyboard.
I have acheived the first part (showing the next line every time I press enter), but I have problem with second part as many STDIN functions read my 'q' input only after I click "ENTER", this is the problem.
This answer https://stackoverflow.com/a/68593092 informed me that STDIN is line-buffered, from which what I understood is that whatever I press on terminal will be stored in a "Buffer" memory (maybe in the form of array? please tell me), and this buffer is pushed into STDIN stream as soon I click "ENTER" and wiped out to intake next line of characters.
If this is true, Is there any way to read from the BUFFER memory directly, instead of waiting for pressing "enter" to push it to STDIN stream and then reading it from STDIN? Or Is there any standard function or any way to achieve this functionality in C?