|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include<stdio.h>
- #include<stdlib.h>
- #include<malloc.h>
- #define L sizeof(struct student) //student结构的大小
- int n; //全局变量,用来记录存放了多少数据
- struct student *studen(); //创建链表
- void print(struct student *head); //打印链表
- struct student
- {
- int num;
- int score;
- struct student *next;
- }
- void main()
- {
- struct student *stu;
- stu=studen();
- print(stu);
- printf("\n\n");
- system("pause");
- }
- struct student *studen()
- {
- struct student *head;
- struct student *p1,*p2;
- p1=p2=(struct student *)malloc(L); //L是student结构的大小
- printf("输入学号num:");scanf("%d",&p1->num);
- printf("输入成绩score:");scanf("%d",&p1->score);
- n=0;
- head=NULL;
- while(p1->num)
- {
- n++;
- if(n==1)
- {
- head=p1;
- }
- else
- {
- p2->next=p1;
- }
- p2=p1;
- p1=(struct student *)malloc(L);
- printf("\n输入学号num:");scanf("%d",&p1->num);
- printf("输入成绩score:");scanf("%d",&p1->score);
- }
- p2->next=NULL;
- return head;
- }
- void print(struct student *head)
- {
- struct student *p;
- printf("\n这里有%d个结点!\n",n);
- p=head;
- if(head)
- {
- do
- {
- printf("学号为 %d 的成绩是:%d\n",p->num,p->score);
- p=p->next;
- }while(p);
- }
- }
复制代码 这里程序指着void main()那一段显示说:E:\1.c(20) : error C2628: 'student' followed by 'void' is illegal (did you forget a ';'?)执行 cl.exe 时出错.
1.exe - 1 error(s), 0 warning(s)
求助?!是哪里错了?
|
|