Вопрос

I get the same string result for curTime and pastTime when I use "ctime" even though the actual values at curTime and pastTime are different by 600 seconds.

How am I getting the same string time for both when using ctime?

thx

struct _timeb timebuffer;

_ftime(&timebuffer);

const time_t  curTime = (const time_t)timebuffer.time;
const time_t  pastTime = curTime - (const time_t)600;

s.Format("%d  %s\n%d  %s", curTime, ctime(&curTime), pastTime, ctime(&pastTime) );
MessageBox(s);
Это было полезно?

Решение

ctime returns a string that can be statically allocated.

So one of your two calls is overwriting the string that the other one generates. You'll need to split that into two print statements, or copy (string copy) the return values of ctime into temporaries.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top