Passing pointer into function, data appears initialized in function, on return appears uninitialize
- by Luke Mcneice
Im passing function GetCurrentDate() the pointer to a tm struct.
Within that function I printf the uninitialized data, then the initialized. Expected results.
However when i return the tm struct appears uninitialized.
See console output bellow. What am i doing wrong?
uninitialized date:??? ???-1073908332
01:9448278:-1073908376 -1217355836
initialized date:Wed May 5 23:08:40
2010
Caller date:??? ???-1073908332
01:9448278:-1073908376 -121735583
int main()
{
test();
}
int test()
{
struct tm* CurrentDate;
GetCurrentDate(CurrentDate);
printf("Caller date:%s\n",asctime (CurrentDate));
return 1;
}
int GetCurrentDate(struct tm* p_ReturnDate)
{
printf("uninitialized date:%s\n",asctime (p_ReturnDate));
time_t m_TimeEntity;
m_TimeEntity = time(NULL); //setting current time into a time_t struct
p_ReturnDate = localtime(&m_TimeEntity); //converting time_t to tm struct
printf("initialized date:%s\n",asctime (p_ReturnDate));
return 1;
}