指针的指针和链表,错在哪里呀
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;
}