Passing pointer into function, data appears initialized in function, on return appears uninitialize

Posted by Luke Mcneice on Stack Overflow See other posts from Stack Overflow or by Luke Mcneice
Published on 2010-05-05T22:21:16Z Indexed on 2010/05/05 22:28 UTC
Read the original article Hit count: 260

Filed under:
|
|

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;
}  

© Stack Overflow or respective owner

Related posts about c

    Related posts about time