Last active
May 23, 2016 22:01
-
-
Save ButchDean/50e54bebca5b83c1a14378f6b017cc75 to your computer and use it in GitHub Desktop.
A countdown timer handy for many things.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <time.h> | |
int main() | |
{ | |
time_t start, now; | |
double secs = 0.0; | |
int timercountdown = 10; | |
start = now = time(NULL); | |
while(1) | |
{ | |
secs = difftime(now, start); | |
if(secs > 1.0) | |
{ | |
if(timercountdown > 0) | |
printf("%d\n", timercountdown); | |
start = now; | |
timercountdown--; | |
if(timercountdown == -1) | |
break; | |
} | |
now = time(NULL); | |
} | |
puts("BOO! Gotcha!"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment