| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 434 人关注过本帖
标题:关于函数声明的问题
只看楼主 加入收藏
学c
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2007-9-17
收藏
 问题点数:0 回复次数:2 
关于函数声明的问题

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

搜索更多相关主题的帖子: 函数 声明 
2007-09-26 15:08
远去的列车
Rank: 1
等 级:新手上路
威 望:2
帖 子:205
专家分:0
注 册:2007-8-7
收藏
得分:0 
加个返回类型,声明和定义的时候都加

void print(struct student *head);



` return(0); //行首多了一点

C++学习
2007-09-26 15:46
学c
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2007-9-17
收藏
得分:0 

不错,谢谢啊!!!!

2007-09-26 16:47
快速回复:关于函数声明的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020340 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved