#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;
}
就好了
相关分类