Advertisement
Guest User

Untitled

a guest
Nov 5th, 2012
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <error.h>
  5. #include <errno.h>
  6.  
  7. void stopwatch(double wait_time)
  8. {
  9.   time_t t1, t2;
  10.  
  11.   for (t1 = t2 = time(NULL); difftime(t2, t1) < wait_time; t2 = time(NULL))
  12.     ;
  13. }
  14.  
  15. int
  16. main(int argc, char **argv)
  17. {
  18.   FILE *fp;
  19.   char buf[100];
  20.   double wait_time;
  21.  
  22.   if (argc != 2)
  23.     error(EXIT_FAILURE, errno, "need filename");
  24.  
  25.   if ((fp = fopen(argv[1], "r")) == NULL)
  26.     error(EXIT_FAILURE, errno, "fopen: ");
  27.  
  28.   while (fscanf(fp, "%lf%100s", &wait_time, buf) != EOF)
  29.   {
  30.     printf("%s\n", buf);
  31.     stopwatch(wait_time);
  32.   }
  33.  
  34.   return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement