From 821cba11365e9bc7546e9581382d5a482e8cdd79 Mon Sep 17 00:00:00 2001 From: Barry Kane Date: Mon, 5 Dec 2022 14:44:16 +0000 Subject: [PATCH] README, and a Year 2038 doomsday clock. --- README.org | 12 ++++++++++++ doomsday-clock-of-doom.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 README.org create mode 100644 doomsday-clock-of-doom.c diff --git a/README.org b/README.org new file mode 100644 index 0000000..505405f --- /dev/null +++ b/README.org @@ -0,0 +1,12 @@ +* Bits and Pieces +Bits and pieces is a repository containing exactly that, bits and pieces of +code. This may include tools that are too small for their own repo, functions +which may be useful in other programs, and pieces to practice various techniques +and concepts. + +These are not guaranteed to be good, stay working, or even work in the first +place. + +Copying and distribution of these files, with or without modification, are +permitted in any medium without royalty. This file is offered as-is, without any +warranty. diff --git a/doomsday-clock-of-doom.c b/doomsday-clock-of-doom.c new file mode 100644 index 0000000..50484c9 --- /dev/null +++ b/doomsday-clock-of-doom.c @@ -0,0 +1,37 @@ +#include +#include +#include +#include +#include + +unsigned long long divideAndCarry(unsigned long long numerator, unsigned long long divisor, unsigned long long * remainder) +{ + *remainder = numerator % divisor; + return numerator / divisor; +} + +void main() +{ + time_t currentTime; + time(¤tTime); + unsigned long long remaining_time, remainder, years, months, days, hours, minutes, seconds; + while(1) + { + time(¤tTime); + remainder = (unsigned long long)difftime(INT_MAX, currentTime); + years = divideAndCarry(remainder, 31557600, &remainder); + months = divideAndCarry(remainder, 2629800, &remainder); + days = divideAndCarry(remainder, 86400, &remainder); + hours = divideAndCarry(remainder, 3600, &remainder); + minutes = divideAndCarry(remainder, 60, &remainder); + seconds = remainder % 60; + printf("\e[1;1H\e[2J"); + printf("= TIME UNTIL THE YEAR 2038 ENDS ALL LIFE ON EARTH =\n\n"); + printf("\tYears: %02d, Months: %02d, Days: %02d\n" + "\tHours: %02d, Minutes: %02d, Seconds: %02d\n\n", + years, months, days, hours, minutes, seconds); + printf("= AAAAAAAAAAAH! IT'S SO VERY SCARY! AAAAAAAAAAAH! =\n"); + sleep(1); + + } +}