View difference between Paste ID: dcpJ2fv5 and 1ZRtnT2i
SHOW: | | - or go back to the newest paste.
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
  if (ferror(fp))
35
    error(EXIT_FAILURE, errno, "ferror: ");
36
  return 0;
37
}