求大神帮忙为什么p一进入循环就变成了无效的指针

#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)//调试的时候在这p变成了无效的地址

{

printf("%s,%d\n",p->name,p->money);

p->next;

}

system("pause");

return 0;

}

//我知道那里错了,输出单个字符用%c,p没有重新赋值导致循环一直不中止改为

while(p!=NULL)

{

printf("%c,%d\n",p->name,p->money);

p = p->next;

}

就好了



慕粉233007138
浏览 1238回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP