Consider the following code;
This code causes an on-screen counter to count away endlessly. It also provides a prompt for the user to input a new number. I want to accept a number from the user and have it stored in the variable "number", then have the counter display restart from that number instantly. I have not been able to implement a way of reading user input that does not pause execution of the code. After hours of experimenting I have come to the conclusion that getchar(), getch(), sscanf(), scanf(), scanw() or any other input statement will pause execution of the program until the input is made. Everything stops and waits for input, including the counter. I want the counter to never stop, just reset itself as directed by the user's input.
int number = 1;
void quitter (void)
int main ( void )
mvaddstr(1,1,"Enter a number: ");
mvprintw (5,5, "%d", number);
number = number + 1 ;
signal (SIGINT, quitter);
//scanw("%d", number); // NO GOOD-FREEZES LOOP
It almost seems that you need 2 programs running independently in parallel, but somehow connected.
Any input statement that allows the program to recognize the fact that the user has entered a number stops the program. Its a catch 22 that I cannot overcome.