改动部分及原因见注释,以下代码可以直接运行
#include
#include
struct student {
char name[20];
int score;
char *passdown;
};
void passOrdown(struct student *); // 这里用到了student,要先声明,所以student
void output(struct student *); // 的定义要放在前面,然后才是函数声明
int main()
{
struct student stu[3];
int i;
for (i=0; i<3; i++) {
printf("请输入第#%d位同学的姓名: ", i+1);
scanf("%s", stu[i].name);
printf("请输入第#%d位同学c语言的分数:", i+1);
scanf("%d", &stu[i].score);
printf("\n");
}
passOrdown(stu);
output(stu);
return 0;
}
void passOrdown(struct student *p)
{
int i;
for (i=0; i<3; i++) {
if (p[i].score >= 60) // p是student的数组 ,不是一个student
p[i].passdown = "pass";
else
p[i].passdown = "down";
}
}
void output(struct student *q)
{
int i;
printf("\n\n%10s %10s %20s\n", "Name", "Score", "Passdown");
for (i=1; i<42; i++)
printf("=");
printf("\n");
for (i=0; i<3; i++) {
printf("%10s %10d %20s\n", q->name, q->score, q->passdown);
q++;
}
}