2 回答

TA貢獻(xiàn)6條經(jīng)驗(yàn) 獲得超0個(gè)贊
struct weapon {
? ? ? ? int price;
? ? ? ? int atk;
? ? ? ? struct weapon * next;
};
struct weapon * create(){
? ? ? ? struct weapon * head;
? ? ? ? struct weapon * p1, *p2;
? ? ? ? int n=0;
? ? ? ? p1=p2=(struct weapon*)malloc(sizeof(struct weapon));
? ? ? ? scanf("%d,%d",&p1->price,&p1->atk);
? ? ? ? head = NULL;
? ? ? ? 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,%d",&p1->price,&p1->atk);
? ? ? ? }
? ? ? ? p2->next = NULL;
? ? ? ? return (head);
}
int main(){
? ? ? ? struct weapon *p;
? ? ? ? p = create();
? ? ? ? int i = 0;
? ? ? ? while(p[i].next != NULL){
? ? ? ? ? ? ? ? printf("Num%d::PRICE:%d,ATK:%d\n",i,p[i].price,p[i].atk);
? ? ? ? ? ? ? ? i++;
? ? ? ? }
? ? ? ? return 0;
}
- 2 回答
- 0 關(guān)注
- 1473 瀏覽
添加回答
舉報(bào)