注册 登录
编程论坛 C语言论坛

error C2078: too many initializers怎么弄

domore 发布于 2019-08-14 08:26, 2432 次点击
只有本站会员才能查看附件,请 登录

#include<stdio.h>
struct Student
    {
    int num;
    char name[20];
    float score;
    };

int main()
    {
    struct Student stu[5]=
        {
        {10010,"Li",80},
        {10015,"Po",90,
        {10020,"Wu",76},
        {10034,"Qi",79},
        {10056,"Zhang",89}
        };
    struct Student temp;
    const int n=5;
    int i,j;
    printf("the order is:\n");
    for(i=0;i<n-1;i++)
        for(j=i+1;j<n;j++)
            if(stu[j].score>stu[i].score)
                {
                temp=stu[i];
                stu[i]=stu[j];
                stu[j]=temp;
                }
    for(i=0;i<n;i++)
        printf("%6d %8s %6.2f\n",stu[i].num,stu[i].name,stu[i].score);
    return 0;
    }
2 回复
#2
rjsp2019-08-14 08:29
{10015,"Po",90,
改为
{10015,"Po",90},
#3
自学的数学2019-08-14 21:54
1