I am not sure if multi threading is the correct term, but here is what I am trying to do. I have a while loop that displays the number 1, pauses, displays the number 2, pauses , displays the number 3 ad infinitum. It just keeps counting.
While the screen displays the sequence of numbers counting up, I also want to display a prompt that says;
"Start counting now from: "
The user can then enter a number and the counter will immediately stop its counting and start counting again from the number entered by the user.
For example if the counter display is up to 22, as soon as the user enters 128 the counter jumps to 128 then continues counting up from 128. The user then enters 5, the counter jumps to 5 then continues counting up from 5.
Thus I need a while loop and a getchar() function to be running at the same time without interfering with each other. Any ideas how I could do this?
Here is the code for my loop, I can't work out where to put the statement
number = getchar();
so it doesn't interfere with the loop and delivers the new value of number instantaneously:
/* backtest02.c */
#include <curses.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
int number = 1;
void quitter(void);
void quitter (void)
{
clear();
mvprintw(2,10, "Quitting...");
refresh();
sleep(4);
endwin();
exit(1);
}
int main ( void )
{
initscr();
while(1)
{
mvprintw (5,5, "%d", number);
refresh();
number = number + 1 ;
sleep(1);
signal (SIGINT, quitter);
}
}