#include <stdio.h>#include <stdlib.h>typedef struct weapon{ char name; int money; struct weapon *next;}lianbiao;int main(void){ lianbiao a,b,c,*head; lianbiao *p; a.name = '1'; a.money = 1; b.name = '2'; b.money = 2; c.name = '3'; c.money = 3; head = &a; a.next = &b; b.next = &c; c.next = NULL; p = head; while(p!=NULL)//調(diào)試的時候在這p變成了無效的地址 { printf("%s,%d\n",p->name,p->money); p->next; } system("pause"); return 0;}//我知道那里錯了,輸出單個字符用%c,p沒有重新賦值導(dǎo)致循環(huán)一直不中止改為while(p!=NULL){printf("%c,%d\n",p->name,p->money);p = p->next;}就好了
求大神幫忙為什么p一進(jìn)入循環(huán)就變成了無效的指針
慕粉233007138
2017-08-05 21:29:47