I am trying to make sense of the following C program :
#include <curses.h>
int main() {
int i;
initscr();
halfdelay(5);
for (i=0; i < 5; i++)
getch();
endwin();
}
But I cannot make sense of it. I understand initscr() initialising the current screen, and that getch() is waiting for user input to unlock the current terminal, but what is the loop and halfdelay() accomplishing here ?
halfdelay(n);sets an input mode where thegetchfunction waitsntenths of a second (in your example program, half a second) for the user to type something.getchreturns the keypress, unless the timer elapses, in which case it returnsERR. This mode can be turned off again withcbreak()ornocbreak().This can be used in code that, e.g., asks the user for confirmation but defaults to some value if they don’t respond within a certain time frame.