作者在 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);
}
唉,烦死了,怎么会出错呢???#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.
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)