为了账号安全,请及时绑定邮箱和手机立即绑定

各位前辈,错那了

各位前辈,错那了

C
溯源1 2017-01-06 14:06:21
#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; elsep2->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);}
查看完整描述

1 回答

已采纳
?
onemoo

TA贡献883条经验 获得超454个赞

最大的问题是:一开始struct weapon的定义的尾大括号后应该有分号。


还有一些小问题(编译器可能会警告,但不会被视为error):

stdio.h 是系统库的头文件,应该用<>括起来。

main函数的返回类型是int,不要写成void。

查看完整回答
反对 回复 2017-01-06
  • 1 回答
  • 0 关注
  • 955 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信