#include<stdio.h>
#include</usr/include/malloc.h>
#define len sizeof(struct student)
struct student
{
long num;
float score;
struct student *next;
};
int n;
int main(void)
{
struct student * creat(); 这里是第一个函数的声明。没问题。
// print(struct student *head); 这里是第二个函数的声明,编译时报错/*malloc.c:17: error: expected expression before 'struct'*/高人给解释一下是为什么?????
struct student *p;
p=creat();
print(p);
` return(0);
}
struct student * creat(void)
{
struct student *p1, *p2;
struct student *head;
n=0;
head=NULL;
p2=p1=(struct student *) malloc(len);
scanf("%ld %f",&p1->num,&p1->score);
while(p1->num!=0)
{
n=n+1;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *) malloc(len);
scanf("%ld %f",&p1->num,&p1->score);
}
p2->next=NULL;
printf("creat successful\n");
return(head);
}
print(struct student *head)
{
struct student *p;
p=head;
while(p!=NULL)
{
printf("%ld %6.2f\n",p->num,p->score);
p=p->next;
}
}
[此贴子已经被作者于2007-9-26 15:14:25编辑过]