corz.org uses cookies to remember that you've seen this notice explaining that corz.org uses cookies, okay!
corz.org text viewer..
[currently viewing: / public/ scripts/ c/ uptime/ uptime-formatted.c - raw]
void main(int argc, char *argv[]) {
long tc, day, hour, min, sec;
day = 0; hour = 0; min = 0; sec = 0;
if (argc > 1) { // there are no arguments!
printf("\n outputs the time since the peecee booted\n");
printf(" in the format \"days,hours,minutes,seconds\"\n");
printf(" specifically designed for parsing\n\n");
printf(" usage: uptime\n\n");
printf(" no additional arguments required!\n");
printf(" v 0.1 (c) corz.org 2005 ->\n");
return 1;
}
// get number of milliseconds PC has been up..
tc = GetTickCount() / 1000; // and convert into seconds
// work out days, etc..
while (tc > 86400) {
day++;
tc -= 86400;
}
while (tc > 3600) {
hour++;
tc -= 3600;
}
while (tc > 60) {
min++;
tc -= 60;
}
while (tc > 1) {
sec++;
tc -= 1;
}
// finally, output uptime to stdout..
printf("%d,%d,%d,%d", day, hour, min, sec);
}
Welcome to corz.org!
Since switching hosts (I hope you are alright, Ed! Wherever you are …) quite a few things seems to be wonky.
Juggling two energetic boys (of very different ages) on Coronavirus lockdown, I'm unlikely to have them all fixed any time soon. Mail me! to prioritise!