<time.h>

OK, I think you guys set me in a trap with “structs” and the <time.h> library - or I’m dummer than others?

I was trying to get a good understanding how things in the <time.h> library work (I think I got the 4million seconds from now challenge done/understood), but there seems to be something strange with the way “time()” works?

Reference the code below, how is it that the “character” variable “time1” gets reassigned the value of the “time2” after the code:

    time(&time2);

//this stuffs current time into the address for time2 - yes?

    charTime2 = ctime(&time2);

//this converts value at “time2” to a character string stuffs it to “charTime2”- yes?

    printf("time2 is %s \n", charTime2);

//This prints my string - yes? Notice NO NEW assignment value for “time1” or “charTime1?” Sooo…wtf?

Full Program:

//
// main.c
// Time.H
//
// Created by Jason on 2/16/16.
// Copyright © 2016 Jason Coster. All rights reserved.
//

#include <stdio.h>
#include <time.h>

time_t timeHolder;
time_t time1;
time_t time2;
time_t time3;
time_t time4;
struct tm timeStruct;
char *charTime1;
char *charTime2;
char *charTime3;

int main(int argc, const char * argv[]) {

time(&time1);
charTime1 = ctime(&time1);
printf("time1 is %s \n", charTime1);


for (long i = 0; i < 2900000000; i++) {
    
 //do nothing for time
}
printf("1**time1 is %s \n", charTime1);


    time(&time2);
    charTime2 = ctime(&time2);
    printf("time2 is %s \n", charTime2);
    
            printf("time1 is %s \n", charTime1);

double timeDifference = difftime(time1, time2);

            printf("3**time1 is %s \n", charTime1);

printf("Time difference is %f \n", timeDifference);


            printf("4**time1 is %s \n", charTime1);


printf("time1 is %s \n", charTime1);

time3 = time1+31536000;

charTime3 = ctime(&time3);

printf("time1 ++ is %s \n", charTime3);

    
    //charTime =

    //printf("diff time is %f \n", difftime);
    
    


return 0;

}