asctime vs asctime_s (deprecated)

Hi ! I'm trying to convert my asctime calls to asctime_s but I'm having trouble with the first parameter...

1
2
3
4
5
6
7
8
9
10
//timestamp 
time_t ltime; /* calendar time */    
ltime = time(NULL); /* get current cal time */

//works fine
m_hDisplayTime.ReplaceSel((LPCTSTR)asctime( localtime(&ltime) ));

//doesnt work at all...
char* buffer;
m_hDisplayTime.ReplaceSel((LPCTSTR)asctime_s(buffer, sizeof(buffer), localtime(&ltime)));


Thanks !!!
The two function have two differenet return types - asctime_s is NOT a direct drop-in replacement for asctime in the way you are trying to do.


Your code to use asctime_s should look something like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
const int buffer_size = 256;//
char buffer[buffer_size]; 
errorno_t error_code;
error_code = asctime_s(buffer, buffer_size, localtime(&ltime)); //do the conversion

if (error_code ==0) //if success
{
     m_hDisplayTime.ReplaceSel(buffer);
}

else
{
       //error occurred in the conversion - do error handling
}


asctime link:
http://msdn.microsoft.com/en-us/library/kys1801b%28v=vs.80%29.aspx
asctime_s link;
http://msdn.microsoft.com/en-us/library/b6htak9c%28v=vs.80%29.aspx
Ahhhhh :)
I have it working now thank you !
Topic archived. No new replies allowed.