- C/C++ code
static int Write(ILog* a_pMe,const char* pFormat,...) { #ifdef _DEBUG_ Loger* pMe=(Loger*)a_pMe; IFile * pFile=pMe->m_pFile; // declare time JulianType pDate; char* pTime; // declare log content. char* pLogContent; char nn[1024]; va_list cArguments; if (pFormat==NULL) return EFAILED; MEMSET(nn,0,1024); //malloc of pointer. pTime=(char*)MALLOC(sizeof(char)*SIZE); pLogContent = (char*)MALLOC(sizeof(char)*SIZE); // get current time and write into file. GETJULIANDATE(0,&pDate); SPRINTF(pTime,"[%4d-%02d-%02d %02d:%02d:%02d]:",pDate.wYear,pDate.wMonth,\ pDate.wDay,pDate.wHour,pDate.wMinute,pDate.wSecond); IFILE_Write(pFile, pTime, STRLEN(pTime)); // 定位是这个地方出了问题!!但是不知道怎么解决 va_start(cArguments, pFormat); VSPRINTF(pLogContent,pFormat,cArguments); SPRINTF(nn,"%s",pLogContent); IFILE_Write(pFile, pLogContent, STRLEN(pLogContent)); va_end(cArguments); //free the pointer FREEIF(pTime) FREEIF(pLogContent); //cut line. IFILE_Write(pFile, "\r\n----------------\r\n", STRLEN("\r\n----------------\r\n")); return SUCCESS; #endif }
这段代码 当调用Write(“logloglog”);时时没有问题的,真机 模拟器也不会出现问题
当时当我 Write(“%s”,“this is a test”);就真机上就出现乱码了!!模拟器是正常的!!!
sdk 3.1.5
vs 2005
各位请指教
------解决方案--------------------
是不是文件中保存UNIcode编码数据啊,所以你看到的是乱码,用Utraedit看看,每个字节是什么东西
------解决方案--------------------
和文件的编码有关系吧