while部分改成如下试试:
while(p != NULL) { q=p->pnext; free(p); p=q; }
p和q交换,然而并没有什么暖用
不好意思,最后找到了,错误是另外一个函数引起的
void main(){
//...
dstmsg(&pmsg);
printf("msglen=%d\n",msglen(pmsg));
}
int msglen(S_MSG* msghead)
{
S_MSG* p = msghead;
int c = 0;
while(p->pnext != NULL)
{
p = p->pnext;
c++;
}
return c;
}
计算msg长度的时候出错,改成下面就正常了:
int msglen(S_MSG* msghead)
{
if(msghead == NULL)
return 0;
S_MSG* p = msghead;
int c = 0;
while(p->pnext != NULL)
{
p = p->pnext;
c++;
}
return c;
}