-
Date Calculations
'lo again you beautiful people you...
I've randomly hit keys and come up with the code below, it's not the final version, as that will require user input and such. I just wondered if the below code was fine, or if it will destroy my computer on the sly, while appearing to be ok?
Code:
#include <stdio.h>
#include <time.h>
#include <conio.h>
int main ( )
{
time_t now, bn, next, first;
struct tm t1, brakes, ins, date;
int freq, brake;
freq = 6;
brake = 3;
now = time(NULL);
t1 = *localtime(&now);
printf( "Now = %s", asctime(&t1) );
t1.tm_mday = 7;
t1.tm_mon = 7;
t1.tm_year = 103;
first = mktime( &t1 );
date = *localtime( &first );
printf( "First Inspection = %s", asctime(&date) );
t1.tm_mday += (freq * 7);
next = mktime( &t1 );
ins = *localtime( &next );
printf( "Next Inspection = %s", asctime(&ins) );
t1.tm_mday += (brake * (freq * 7));
bn = mktime( &t1 );
brakes = *localtime( &bn );
printf( "Brake = %s", asctime(&brakes) );
t1 = *localtime(&now);
getch();
return 0;
}
As always, thanks for any comments...
-
That'll do me... And It'll be fine till I get to the user input bit.... :rolleyes:
Thanking you, Good Sir...