MSC delay() routine?

Randy Azarian azarian at hpcc01.HP.COM
Sat Mar 10 11:14:31 AEST 1990


Does anyone have a delay routine written in C?

I don't need something very accurate.  If I say delay(3) I want it to 
pause execution for approximately 3 seconds.

(Anything more accurate would be suitable).


Here is what I have.  It works, but it isn't too consistant. 
If I say delay(1), sometimes I get a delay for one second, and sometimes I 
get a microsecond delay.

delay(n)
int n;
{
  struct dostime_t time1, time2;
  int i;
  unsigned long one,two;

  _dos_gettime(&time1); time2=time1;
  one = (time1.hour*3600) + (time1.minute*60) + time1.second;
  two = (time2.hour*3600) + (time2.minute*60) + time2.second;
  while ((two - one) < n) {
    _dos_gettime(&time2);
    two = (time2.hour*3600) + (time2.minute*60) + time2.second;
  }
}



More information about the Comp.lang.c mailing list