当前位置: 代码迷 >> C语言 >> 关于函数声明的问题
  详细解决方案

关于函数声明的问题

热度:361   发布时间:2007-09-26 15:08:07.0
关于函数声明的问题

#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编辑过]

搜索更多相关的解决方案: 函数  声明  

----------------解决方案--------------------------------------------------------
加个返回类型,声明和定义的时候都加

void print(struct student *head);



` return(0); //行首多了一点
----------------解决方案--------------------------------------------------------

不错,谢谢啊!!!!


----------------解决方案--------------------------------------------------------
  相关解决方案