指针的指针和链表,错在哪里呀

pan2008 2003-08-20 10:22:21
struct stcMsg
{
int num;
long nSize;
char**pMsg;
struct stcMsg*pNext;
};

int m_nSize; //对应数据项nSize
struct stcMsg* m_pHeadMsg; //头节点
................................................

void AddMsg(int num,int nSize)
{
char*msgBuf=new char[nSize];//分配nSize个存char的空间

struct stcMsg* pNew=new struct stcMsg;

pNew->num=num;
pNew->nSize=nSize;
pNew->pMsg=&msgBuf;
pNew->pNext=m_pHeadMsg;
m_pHeadMsg=pNew;
}

char* FindMsg(int num)
{
m_nSize=0;

struct stcMsg*pStcMsg=m_pHeadMsg;

while (pStcMsg!=NULL)
{
if(pStcMsg->num==num)
{
m_nSize=pStcMsg->nSize;
return *(pStcMsg->pMsg);//返回总不是所期望的,不知何故
}

pStcMsg=pStcMsg->pNext;
}
return NULL;
}
...全文
63 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

69,336

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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