写文件乱码问题!!模拟器没有问题,真机乱码!!!!

nuist320 2010-07-01 11:45:37

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


各位请指教
...全文
1807 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
nuist320 2010-07-05
  • 打赏
  • 举报
回复
谢谢!!!问题已经解决!!把解决方法贴出来!!
把出问题的这些代码
    va_start(cArguments, pFormat);
VSPRINTF(pLogContent,pFormat,cArguments);
SPRINTF(nn,"%s",pLogContent);
IFILE_Write(pFile, pLogContent, STRLEN(pLogContent));
va_end(cArguments);

替换成

va_start(cArguments,pFormat);
do
{
c =*pFormat;
if (c != '%')
{
SPRINTF(StringChar,"%c",c); //照原样输出字符
STRCAT (finalString,StringChar);
}
else
{
//按格式字符输出数据
switch(*++pFormat)
{
case'd':
temp=va_arg(cArguments,int);
SPRINTF(StringChar,"%d",temp);
STRCAT(finalString,StringChar);
break;
case's':
tempString= va_arg(cArguments,char*);
STRCAT(finalString,tempString);

break;
default:
break;
}

}
++pFormat;
MEMSET(StringChar,0,64);
}while (*pFormat != '\0');


由于是自己扩展的 所以目前只支持%s 和%d 如果有需要 可以自己扩展
FLYUP_CHEN 2010-07-01
  • 打赏
  • 举报
回复
和文件的编码有关系吧
儿大不由爷 2010-07-01
  • 打赏
  • 举报
回复
是不是文件中保存UNIcode编码数据啊,所以你看到的是乱码,用Utraedit看看,每个字节是什么东西
nuist320 2010-07-01
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 chenmeimei_8899 的回复:]

和文件的编码有关系吧
[/Quote]


应该和编码没关系吧!!!不然我调用Write(“logloglog”);也应该是乱码!!但现在是正常的。 只有Write(“%s”,“this is a test”)这个是乱码

3,477

社区成员

发帖
与我相关
我的任务
社区描述
本论坛以AI、WoS 、XR、IoT、Auto、生成式AI等核心板块组成,为开发者提供便捷及高效的学习和交流平台。 高通开发者专区主页:https://qualcomm.csdn.net/
人工智能物联网机器学习 技术论坛(原bbs) 北京·东城区
社区管理员
  • csdnsqst0050
  • chipseeker
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧