在这个c语言程序里我想让所有不合格的人都输出,但返回时只能返回一个值,怎么改进一下,求指导
完整代码如下:
print函数你没贴全,你自己补充进来吧。
#include <stdio.h>
#define N 3
struct student
{
int num;
char name[20];
float score[3];
float ts;
};
int main()
{
void input(struct student stu[]);
void print(struct student stu);
void leave(struct student stu[]);
struct student stu[N],*p;
p = stu;
input(p);
leave(p);
return 0;
}
void input(struct student stu[])
{
int i;
printf("请输入各学生信息:学号、姓名,3门课成绩:\n");
for (i = 0;i<N;i++)
{
scanf("%d%s%f%f%f",&stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
stu[i].ts = stu[i].score[0]+stu[i].score[1]+stu[i].score[2];
}
}
void print(struct student stu)
{
//你的代码
}
void leave(struct student stu[])
{
int i;
for(i=0;i<N;i++)
{
if(stu[i].ts < 150)
{
print(stu[i]);
//m = i;
}
}
//return stu[m];
}
如果有多个不合格的人,那你返回哪一个呢?
int main()
{
void input(struct student stu[]);
void leave(struct student stu[]);
void print(struct student stud);
struct student stu[N];
struct student *p = stu;
input(p);
leave(p);
return 0;
}
void leave(struct student stu[])
{
for(int i=0;i<N;i++)
{
if(stu[i].ts < 150)
printf(stu[i]);
}
}