README, and a Year 2038 doomsday clock.

This commit is contained in:
Barry Kane 2022-12-05 14:44:16 +00:00
commit 821cba1136
2 changed files with 49 additions and 0 deletions

12
README.org Normal file
View File

@ -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.

37
doomsday-clock-of-doom.c Normal file
View File

@ -0,0 +1,37 @@
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>
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(&currentTime);
unsigned long long remaining_time, remainder, years, months, days, hours, minutes, seconds;
while(1)
{
time(&currentTime);
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);
}
}