Date Calculations

This is a discussion on Date Calculations within the C Programming forums, part of the General Programming Boards category; 'lo again you beautiful people you... I've randomly hit keys and come up with the code below, it's not the ...

  1. #1
    Registered User Inept Pig's Avatar
    Join Date
    Apr 2002
    Posts
    140

    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...
    Money frees you from doing things you dislike. Since I dislike doing nearly everything, money is handy - Groucho Marx

  2. #2
    Registered User Inept Pig's Avatar
    Join Date
    Apr 2002
    Posts
    140
    That'll do me... And It'll be fine till I get to the user input bit....

    Thanking you, Good Sir...
    Money frees you from doing things you dislike. Since I dislike doing nearly everything, money is handy - Groucho Marx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advancing day by day until it matches a second date
    By nhubred in forum C++ Programming
    Replies: 1
    Last Post: 05-30-2009, 09:55 AM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 04:25 PM
  3. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 05:23 PM
  4. CDate Class - handle date manipulation simply
    By LuckY in forum C++ Programming
    Replies: 5
    Last Post: 07-16-2003, 09:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21