cxx0030 错误 无法计算表达式的值

C++语言 码拜 8年前 (2016-06-07) 2541次浏览
void GameLogic::WriteReplayTxt(FactoryPlayerNodeDef *pPlayerNode, void * pMsg,int iMsgType,int iMsgLen)
{
if (pPlayerNode == NULL)
{
return;
}
int iRoomNum = pPlayerNode->cRoomNum;
int iTableNum = pPlayerNode->cTableNum;
FactoryTableItemDef *pTableItem = GetTableItem(iRoomNum-1,iTableNum-1);
EventMsgClientDef msgReplay;
memset(&msgReplay,0,sizeof(EventMsgClientDef));
MsgHeadDef *msgHead = (MsgHeadDef*)pMsg;
msgHead->cVersion = MESSAGE_VERSION;
msgHead->cMsgType = iMsgType;
msgHead->iMsgBodyLen = htonl(iMsgLen-sizeof(MsgHeadDef));
msgReplay.iType = 0;//普通消息
msgReplay.iIndex = pPlayerNode->iSocketIndex;
msgReplay.iDataLen = iMsgLen;
memcpy(msgReplay.msgData,pMsg,iMsgLen);
char *pDir = “replay”;
//CreateDirectory(pDir);
char *szReplayPath;
memset(szReplayPath,0,sizeof(szReplayPath));
sprintf(szReplayPath,”%s\%s.txt”,pDir,pTableItem->m_szRoundIndex);
_log(_ERROR,”CallBackReadyReqLogic”,”szReplayPath [%s]”,szReplayPath);
fReplay = fopen(szReplayPath,”a+”);
if (fReplay == NULL)
{
_log(_ERROR,”WriteReplayTxt”,”写数据出错”);
return;
}
else
{
//保存useid,座位号,消息体,消息类型,消息长度
int res = fprintf(fReplay,”%d;%d;%s;%d;%d\n”,pPlayerNode->iUserID,pPlayerNode->cTableNumExtra,msgReplay.msgData,iMsgType,msgReplay.iDataLen);
if (res<0)
{
_log(_ERROR,”CallBackReadyReqLogic”,”又写数据出错”);
fclose(fReplay);
return;
}
fclose(fReplay);
//fprintf(fReplay,”iType %d;iIndex %d;iDataLen %d;msgData %s”,msgReplay->iType,msgReplay->iIndex,msgReplay->iDataLen,msgReplay->msgData);
}
}
这个function在一个循环中调用,在第二次调用的时候,就弹出 cxx0030 错误 无法计算表达式的值,然后在char *szReplayPath;这个位置崩溃,请高手给个帮助。
解决方案

40

char *szReplayPath;
memset(szReplayPath,0,sizeof(szReplayPath));
sprintf(szReplayPath,”%s\%s.txt”,pDir,pTableItem->m_szRoundIndex);
有问题吧!
szReplayPath是一个字符指针,保存的是地址,可能只占有4个字节吧!不能文件的路径保存在它下面;
声明为字符数组吧!char szReplayPath[200];

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明cxx0030 错误 无法计算表达式的值
喜欢 (0)
[1034331897@qq.com]
分享 (0)