Multi threading?

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);
}

}

select driven loop.....

static char buf[256];
char *p=buf;
long count;

while (1)  {
  fd_set fdr;
  struct timeval to;
  FD_ZERO(&fdr);
  FD_SET(0,&fdr);

   to.tv_sec=1;
   to.tv_usec=0;

   if (select(1,&fdr,NULL,NULL,&to)>0)
   { 
        if (FD_ISSET(0,&fdr))
        {
              char c;
             if (1==read(0,&c,1))
             {
                 *p++=c;
                 *p=0;
                  if (c=='\n') 
                  {
                      count=atol(buf);
                      p=buf;
                  }  
             }
        }
    }
    else
    {
         count++;
        printf("%ld\n",count);
    }
}

Thanks for your effort. I must admit your code is a bit beyond my capabilities at the moment, however I will examine it and learn. I was hoping I could just slot a getchar() statement in somewhere and it would read a new integer for use in the loop. Apparently it is not that simple.

Um, it's already done, "read" is reading from stdin, when we get a newline then the atol() will convert the string into the new count.

A typo in the code of Porter:

struct timeval tv;

must be:

struct timeval to;

Regards