summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-02-02 14:20:05 -0500
committerHolden Rohrer <hr@hrhr.dev>2020-02-02 14:35:43 -0500
commit37ab49b2706f524f3a05ac7cc96ee1e94d482dda (patch)
treedf145be3a39e6a94364cc757fb6de22fef31a612
parent493f99109166c37feb58d0826de9a54880cb75b8 (diff)
added multi-call support (improved err messaging)
-rw-r--r--timer.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/timer.c b/timer.c
index 0e4ce7c..ad479e7 100644
--- a/timer.c
+++ b/timer.c
@@ -1,16 +1,26 @@
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
int main(int argc, char** argv){
int min; int sec;
- if (argc != 2) return 1;
+ if (argc < 2){
+ perror("format: `timer mins:secs [# of timers to run]`");
+ return 1;
+ }
+ int times = 1;
+ if (argc >= 3){
+ sscanf(argv[2], "%d", &times);
+ }
sscanf(argv[1], "%d:%d", &min, &sec);
int time = min*60 + sec;
- for (int i = 1; i<=time; i++){
- printf("%d:%02d/%d:%02d\r", (i-i%60)/60, i%60, min, sec);
- fflush(stdout);
- sleep(1);
+ for (int j = 0; j<times; j++){
+ for (int i = 1; i<=time; i++){
+ printf("%d:%02d/%d:%02d\r", (i-i%60)/60, i%60, min, sec);
+ fflush(stdout);
+ sleep(1);
+ }
+ printf("\n");
}
- printf("\n");
return 0;
}