鱼C论坛

 找回密码
 立即注册
查看: 6622|回复: 4

error C2628 求助!

[复制链接]
发表于 2013-7-30 18:37:04 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<malloc.h>

  4. #define L sizeof(struct student)   //student结构的大小

  5. int n;    //全局变量,用来记录存放了多少数据

  6. struct student *studen();                  //创建链表
  7. void print(struct student *head);         //打印链表

  8. struct student
  9. {
  10.         int num;
  11.         int score;
  12.         struct student *next;
  13. }


  14. void main()
  15. {
  16.         struct student *stu;
  17.         stu=studen();
  18.         print(stu);
  19.         printf("\n\n");
  20.         system("pause");
  21. }

  22. struct student *studen()
  23. {
  24.         struct student *head;
  25.         struct student *p1,*p2;

  26.         p1=p2=(struct student *)malloc(L);        //L是student结构的大小

  27.         printf("输入学号num:");scanf("%d",&p1->num);
  28.         printf("输入成绩score:");scanf("%d",&p1->score);
  29.         n=0;
  30.         head=NULL;
  31.         while(p1->num)
  32.         {
  33.                 n++;
  34.                 if(n==1)
  35.                 {
  36.                         head=p1;
  37.                 }
  38.                 else
  39.                 {
  40.                         p2->next=p1;
  41.                 }
  42.                 p2=p1;
  43.                 p1=(struct student *)malloc(L);

  44.                 printf("\n输入学号num:");scanf("%d",&p1->num);
  45.             printf("输入成绩score:");scanf("%d",&p1->score);
  46.         }
  47.         p2->next=NULL;
  48.         return head;
  49. }

  50. void print(struct student *head)
  51. {
  52.         struct student *p;
  53.         printf("\n这里有%d个结点!\n",n);

  54.         p=head;
  55.         if(head)
  56.         {
  57.                 do
  58.                 {
  59.                         printf("学号为 %d 的成绩是:%d\n",p->num,p->score);
  60.                         p=p->next;
  61.                 }while(p);
  62.         }
  63. }
复制代码
这里程序指着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)
求助?!是哪里错了?

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-7-30 19:05:06 | 显示全部楼层
提示那么明显。。。
struct student{
...
};        //这里的分号
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2013-7-30 20:58:35 | 显示全部楼层
17行少了个分号
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-7-31 11:49:37 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-7-31 11:50:19 | 显示全部楼层
codefu 发表于 2013-7-30 20:58
17行少了个分号

谢谢~~~~~~~
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-17 07:24

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表