求解这段代码哪里错了
时间:10-02
整理:3721RD
点击:
#include<stdio.h>
struct stu
{
int num;
char name;
char sex;
float fen;
}lin[3]={
{2,"lin huan",'M',100},
{3,"xiao ming",'M',90},
{4,"xiao fang",'F',80},
};
main()
{
struct stu *sp;
sp=lin;
void max(sp);
}
void max(struct stu *ss);
void max(struct stu *ss)
{
float ave;
float s=0;
char c=0;
int i;
for(i=0;i<3;i++)
{
s=s+(ss->fen);
if(ss->fen<60)
{
c=c+1;
}
ss++;
}
ave=s/3;
printf("%f\t",ave);
printf("%d\t",c);
}
struct stu
{
int num;
char name;
char sex;
float fen;
}lin[3]={
{2,"lin huan",'M',100},
{3,"xiao ming",'M',90},
{4,"xiao fang",'F',80},
};
main()
{
struct stu *sp;
sp=lin;
void max(sp);
}
void max(struct stu *ss);
void max(struct stu *ss)
{
float ave;
float s=0;
char c=0;
int i;
for(i=0;i<3;i++)
{
s=s+(ss->fen);
if(ss->fen<60)
{
c=c+1;
}
ss++;
}
ave=s/3;
printf("%f\t",ave);
printf("%d\t",c);
}
1、结构体定义错误,char name; 这里应该是数组才对
2、主函数main里函数调用void max(sp);没有void
楼上说的是正确的,还有声明子函数的时候要放在main函数之前,不然就直接把子函数放在main函数之前就能够编译通过了。最主要是结构体定义错误了
把char name 改成char name[] 就可以了
都说这么多了,还没解决吗