summaryrefslogtreecommitdiff
path: root/timer.c
blob: 6467ce8760310e9f04f95cdf39e8e2bb09c41442 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char** argv){
  int min; int sec;
  if (argc < 2){
    perror("format: `timer mins:secs [# of timers to run]`");
    return 1;
  }
  int times = 0;
  if (argc >= 3){
    sscanf(argv[2], "%d", &times);
  }
  sscanf(argv[1], "%d:%d", &min, &sec);
  int time = min*60 + sec;
  for (int j = 0; times==0 || j<times; j++){
    for (int i = 1; i<=time; i++){
      printf("\r%d:%02d/%d:%02d", (i-i%60)/60, i%60, min, sec);
      fflush(stdout);
      sleep(1);
    }
    printf("\a\n");
  }
  return 0;
}