corz.org front page. welcome! cor's blog, aka 'corzblog'. I write stuff here.. downloads of all shapes and sizes, documents, secret chasms, you name it.. developing sites, software, stuff.. updates generally get posted here. music is everywhere, sometimes I pin it down.. soul-candy, captured things you can look at.. 'Mathematics For Women' copyright Cor 1994 ;o)
the power to serve, at home or anywhere. webmasters tricks, tips, tools and resources. the devil's work, or a capable multimedia desktop, you decide..
information and search
contact page for corz.org, ways to get $hit to me.. get a print friendly version of this page, probably.. Put YOUR money where MY mouth is!
 
corz.org text viewer..
[currently viewing: /public/scripts/c/uptime/uptime-formatted.c - raw]
 
#include <stdio.h>
#include <windows.h>

/*
    uptime v0.1
    
    outputs uptime to stdout in a simple, parsable format.
    this program is designed for trivial usage, forum
    signatures and suchlike.
    
    ;o)
    (or
*/


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);
}