为什么我的程序运行的时候显示Segmentation fault (core dumped)
#include <stdio.h>
#include <malloc.h>
struct weapon {
int price;
struct weapon *next;
};
struct weapon *create(){
struct weapon *p1,*p2,*head;
p2=p1=(struct weapon*)malloc(sizeof(struct weapon));
return 0;
scanf("%d",&p1->price);
head=NULL;
int n=0;
while(p1->price != 0){
n++;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct weapon*)malloc(sizeof(struct weapon));
scanf("%d",&p1->price);
}
p2->next = NULL;
return (head);
}
int main(){
struct weapon *p;
p=create();
printf("%d",p->price);
return 0;
}