錯哪了,各位前輩
/* Note:Your choice is C IDE */
#include "stdio.h"
#include<malloc.h>
struct weapon{
int atk;
int price;
struct weapon * next;
}
struct weapon*create()//空格不是問題
{
int a=0;
struct weapon *p1,*p2,*head;
p1=p2=(struct weapon*)malloc(sizeof(struct weapon));
scanf("%d%d",&p1->atk,&p1->price);
while(p1->atk!=0)
{
a++;
if(a==1)//==
head=p1;
?
else
p2->next=p1;
p2=p1;
p1=(struct weapon*)malloc(sizeof(struct weapon));
scanf("%d%d",&p1->atk,&p1->price);//指針用->
}
? p2->next=NULL;
return (head);
}
void main()
{
struct weapon *p;
p=create();
? ? printf("%d%d",p->atk,p->price);
}
2017-01-07
結構體定義語句后面沒有加分號
scanf 和 printf 語句的數據輸入之間沒有加分隔符
建立鏈表時頭指針head要為NULL