Why doesn't this work
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void setTime(time_t *curTime,struct tm *retDate);
int main(int argc, char *argv[])
{
time_t now = 0;
struct tm *curDate;
/* This would work
now = time(NULL);
curDate = localtime(&now);
*/
printf("main()-Before:\ntime_t now: %x\tstruct tm *curDate: %x\n\n\n",&now,curDate);
setTime(&now,curDate);
printf("main()-After:\ntime_t now: %x\tstruct tm *curDate: %x\n\n\n",&now,curDate);
printf("%d\n\n",curDate->tm_hour);
system("PAUSE");
return 0;
}
void setTime(time_t *curTime,struct tm *retDate)
{
printf("setTime()-Before:\ntime_t now: %x\tstruct tm *curDate: %x\n\n\n",curTime,retDate);
*curTime = time(NULL);
retDate = localtime(curTime);
printf("setTime()-After:\ntime_t now: %x\tstruct tm *curDate: %x\n\n\n",curTime,retDate);
}
I don't get why this doesn't work... i'm no newb to C either so it's really disturbing me. Is there some kind out scope error with localtime? but retDate is a pointer to curDate which is in scope. Compile it and you'll see that it has the right numbers while in setTime(), but when it goes back to main() it looses the correct memory area. Thanks to all who read this and/or help, I truely appriciate it.