I'm trying to do a book borrowing system witch can tell the user the day that they have to return the book. Because I have to use the data to check if the borrowing times are exceeding limit or not. I try to use two tm structures.
struct tm *Olddate;
struct tm *Newdate;
I added days to one of the structure like this
Newdate->tm_mday += 7;
When I tried to print out the two different struct, the output are somehow the same.
printf("Current local time and date: %s", asctime(Olddate));
printf("Current new time and date: %s", asctime(Newdate));
Output:
Current local time and date: Tue May 17 21:37:16 2022
New time and date: Tue May 17 21:37:16 2022
Minimal reproducible example:
#include <stdio.h>
#include <time.h>
int main () {
time_t rawtime;
struct tm *Olddate;
struct tm *Newdate;
time( &rawtime );
Olddate = localtime(&rawtime);
Newdate = localtime(&rawtime);
Newdate->tm_mday += 7;
printf("Current local time and date: %s", asctime(Olddate));
printf("New time and date: %s", asctime(Newdate));
return 0;
}