Can I implement the ctime struct tm in c and in the same tim
Can I implement the ctime struct tm in c++ and in the same time set the time manually passing the values . Ex setTime(2,25,32).??
Solution
Yes it can implemented using mktime function ...
Below is sample example for setting day month and year
 /* mktime example: weekday calculator */ #include <stdio.h> /* printf, scanf */ #include <time.h> /* time_t, struct tm, time, mktime */ int main () { time_t rawtime; struct tm * timeinfo; int year, month ,day; const char * weekday[] = { \"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"}; /* prompt user for date */ printf (\"Enter year: \"); fflush(stdout); scanf (\"%d\",&year); printf (\"Enter month: \"); fflush(stdout); scanf (\"%d\",&month); printf (\"Enter day: \"); fflush(stdout); scanf (\"%d\",&day); /* get current timeinfo and modify it to the user\'s choice */ time ( &rawtime ); timeinfo = localtime ( &rawtime ); timeinfo->tm_year = year - 1900; timeinfo->tm_mon = month - 1; timeinfo->tm_mday = day; /* call mktime: timeinfo->tm_wday will be set */ mktime ( timeinfo ); printf (\"That day is a %s.\ \", weekday[timeinfo->tm_wday]); return 0; }

