#include <stdio.h>
#include <stdlib.h>
void passOrdown(struct student *);
void output(struct student *);
struct student {
char name[20];
int score;
char *passdown;
};
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->score >= 60)
p->passdown = "pass";
else
p->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++;
}
}
改动部分及原因见注释,以下代码可以直接运行
#include <stdio.h>
#include <stdlib.h>
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++;
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。