home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / C / TIMER / SLEEP.C < prev    next >
C/C++ Source or Header  |  1993-12-01  |  625b  |  36 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "timer.h"
  4.  
  5. unsigned long sleep();
  6. main (int argc, char ** argv)
  7.     {
  8.     long pause;
  9.     unsigned long time;
  10.  
  11.     if (argc < 2)
  12.         {
  13.         fprintf (stderr, "Usage: sleep <time in milliseconds>\n");
  14.         exit (0);
  15.         }
  16.  
  17.     pause = atol (argv[1]);
  18.     time = sleep (pause);
  19.     printf ("%ld\n", time);
  20.     }
  21.  
  22. unsigned long sleep (long pause)
  23.     {
  24.     long start, stop;
  25.     unsigned long time;
  26.     
  27.     initializetimer ();
  28.     start = readtimer();
  29.     time = 0.0;
  30.     while (elapsedtime (start, stop = readtimer()) < pause)
  31.         ;
  32.     restoretimer();
  33.     time = elapsedtime (start, stop);
  34.     return (time);
  35.     }
  36.