链表为什么会出错啊!!!!

作者在 2011-02-13 16:06:02 发布以下内容
#include<stdio.h>
#include<stdlib.h>
#define LEN sizeof(struct student)
    struct student
    {
        int num;
        float score;
        struct student *next;
    }
    int n;
    struct student *creat(void)
    {
        struct student *head;
        struct student *p1,*p2;
        head=NULL;
        n=0;
        p1=p2=(struct student*)malloc(LEN);
        scanf("%d,%f",&p1->num,&p1->score);
        while(p1->num!=0)
        {n=n+1;
            if(n==1)head=p1;
            else p2->next=p1;
            p1=(struct student*)malloc(LEN);
            scanf("%d,%f",p1->num,&p1->score);
        }
        p2->next=NULL;
        return(head);
    }
唉,烦死了,怎么会出错呢???
错误提示这样
--------------------Configuration: porgram_lianbiao - Win32 Debug--------------------
Compiling...
porgram_lianbiao.c
D:\刘远见\MSDev98\porgram_lianbiao\porgram_lianbiao.c(10) : error C2628: 'student' followed by 'int' is illegal (did you forget a ';'?)
D:\刘远见\MSDev98\porgram_lianbiao\porgram_lianbiao.c(16) : error C2115: '=' : incompatible types
D:\刘远见\MSDev98\porgram_lianbiao\porgram_lianbiao.c(20) : error C2088: '+' : illegal for struct
D:\刘远见\MSDev98\porgram_lianbiao\porgram_lianbiao.c(21) : error C2088: '==' : illegal for struct
Error executing cl.exe.
porgram_lianbiao.obj - 4 error(s), 0 warning(s)
 
Me | 阅读 1318 次
文章评论,共6条
lyj23(作者)
2011-02-14 09:47
1
谁说#define 那里错了,你自己也不太懂吧,预处理又没在那里用!你仔细想想吧!
闭眼到天黑
2011-02-20 14:12
2
麻烦你把书再看一遍吧,认真学习基础知识!
韩明海
2011-02-22 13:13
3
有主函数么?
一纸空白zj
2011-02-23 22:05
4
什么情况???
尤慕思
2011-02-26 23:56
5
最后的scanf函数写错了,应该改为scanf(&quot;%d,%f&quot;,&amp;p1-&gt;num,&amp;p1-&gt;score);<br />
你忘了寻址符&nbsp;&nbsp;&amp;&nbsp;&nbsp;了。是吧???<br />
还有结构体类型后应该有分号,即struct student<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;int num;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;float score;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;struct student *next;<br />
&nbsp; &nbsp; };
明晟
2011-03-05 15:55
6
struct student<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;int num;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;float score;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;struct student *next;<br />
&nbsp; &nbsp; };<br />
大哥,少一个分号!!!<br />
另外没有主函数、
游客请输入验证码
浏览2432次
文章分类