c语言结构体数组无法运行?

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++;
}
}

原文阅读

"文章为作者独立观点, 不代表老订阅立场"

本站作者

每日荐书

在不完美的世界力求正常——读《公司的坏话》

书名:《公司的坏话》

作者:李天田(脱不花妹妹)

出版社:北京大学出版社

赞助商

广告