是用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

解决方案 »

  1.   

    CTime time = CTime::GetCurrentTime();
    CString strTime;
    strTime.Format(_T("%04d-%02d-%02d-%02d-%02d-%02d"), 
                  time.GetYear(), time.GetMonth(), time.GetDay(), 
      time.GetHour(), time.GetMinute(), time.GetSecond());
      

  2.   

    unsigned char szProcLogFile[100000]; //xf20040311
    ok!
      

  3.   

    char buffer[20];
       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'也没问题。
      

  4.   

    VC1.0不支持长文件名,所以用fopen打开文件时文件名就被截断了
      

  5.   

    因为要开发16位的DLL文件,所以用了VC1.0
    该如何解决这个问题?