I am coding a terminal like Linux terminal with C under Linux OS and I need to quit program when the user presses ctrl+D keywords. But I don’t know how to understand that the user pressed these keywords. Thanks for your helping.
I’m getting inputs with fgets()
Ctrl+D is end-of-file. In that case,
fgets()will return a null pointer.So, your program’s main loop can probably look something like this:
Note that this only works for simple buffered input. For information on lower-level keyboard handling, check out http://tldp.org/HOWTO/Keyboard-and-Console-HOWTO.html