为什么我的结果不是1,1而是3,3
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
struct weapon
{
int price;
int damage;
struct weapon *next;
};
struct weapon *create()
{
struct weapon *p1,*p2,*head;
int i=0;
p1 = p2 = (struct weapon*)malloc(sizeof(struct weapon));
head = NULL;
scanf_s("%d %d",&p1->price,&p1->damage);
while(0!=p1->price)
{
i++;
if( i = 1)
{
head = p1;
}
else
{
p2->next = p1;
}
p2 = p1;
p1 = (struct weapon*)malloc(sizeof(struct weapon));
scanf_s("%d %d",&p1->price,&p1->damage);
}
p2->next = NULL;
return (head);
}
int main(void)
{
struct weapon *p;
p = create();
printf("%d,%d",p->price,p->damage);
system("pause");
return 0;
}