Skip to content

Instantly share code, notes, and snippets.

@ButchDean
Last active May 23, 2016 22:01
Show Gist options
  • Save ButchDean/50e54bebca5b83c1a14378f6b017cc75 to your computer and use it in GitHub Desktop.
Save ButchDean/50e54bebca5b83c1a14378f6b017cc75 to your computer and use it in GitHub Desktop.
A countdown timer handy for many things.
#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