

#include <stdio.h>
struct weapon{
int price;
int atk;
struct weapon * next;
};
int main()
{
struct weapon a,b,c, *head;
a.price = 100;
a.atk = 100;
b.price = 200;
b.atk = 200;
c.price = 300;
c.atk = 300;
head = &a;
a.next = &b;
b.next = &c;
c.next = NULL;
struct weapon *p;
while(p!=NULL){
printf("%d,%d\n",p->price,p->atk);
p=p->next;
}
return 0;
}请问哪里导致的错误??。。。
如果你不想使用P,可以直接用head来代替p,我试过结果一样
p要让其指向head,不然谁知道你这个p 是 干嘛的呢
要让head指向p
p=head;