是用VC1.0在WIN98下编译,使用
static unsigned char szProcLogFile[60]; //xf20040311
unsigned char szTime[20];
.
.
.
vGetTime(szTime);//调用下面的函数void vGetTime(unsigned char *pszTime)
sprintf(szProcLogFile, "c:\\windows\\tmpdata\\测试数据-%.10s.XH", szTime+4);
fp=fopen(szProcLogFile,"a+");
为什么,最后生成的文件名是“测试数据-03”(连扩展名都没有,似乎被截掉了),而不是“测试数据-0318103021.XH”(0318103021指月日小时分秒固定10位)
//xf20040315_start
void vGetTime(unsigned char *pszTime)
{
time_t t;
struct tm tm; t= time( NULL );
memcpy(&tm, localtime(&t), sizeof(struct tm));
sprintf((char *)pszTime, "%04d%02d%02d%02d%02d%02d",
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
}
//xf20040315_end
static unsigned char szProcLogFile[60]; //xf20040311
unsigned char szTime[20];
.
.
.
vGetTime(szTime);//调用下面的函数void vGetTime(unsigned char *pszTime)
sprintf(szProcLogFile, "c:\\windows\\tmpdata\\测试数据-%.10s.XH", szTime+4);
fp=fopen(szProcLogFile,"a+");
为什么,最后生成的文件名是“测试数据-03”(连扩展名都没有,似乎被截掉了),而不是“测试数据-0318103021.XH”(0318103021指月日小时分秒固定10位)
//xf20040315_start
void vGetTime(unsigned char *pszTime)
{
time_t t;
struct tm tm; t= time( NULL );
memcpy(&tm, localtime(&t), sizeof(struct tm));
sprintf((char *)pszTime, "%04d%02d%02d%02d%02d%02d",
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
}
//xf20040315_end
CString strTime;
strTime.Format(_T("%04d-%02d-%02d-%02d-%02d-%02d"),
time.GetYear(), time.GetMonth(), time.GetDay(),
time.GetHour(), time.GetMinute(), time.GetSecond());
ok!
time_t t;
struct tm tm; t= time( NULL );
memcpy(&tm, localtime(&t), sizeof(struct tm));
sprintf((char *)buffer, "%04d%02d%02d%02d%02d%02d\0",
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
cout<<buffer<<endl;
测了一下没问题啊,加了'\0'也没问题。
该如何解决这个问题?