int main()
{struct stu
{
int number;
stu *course;
double score;
};
int i;
struct stu student[4];
printf("请输入各学生学号及成绩:\n");
for(i=0;i<4;i++)
{scanf("%d%lf,%lf,%lf,%lf,%lf",&student[i].number,&student[i].course[0].score,&student[i].course[1].score,&student[i].course[2].score,&student[i].course[3].score,&student[i].course[4].score);
printf("\n");}
return 0;
}
scanf读取根本不成功,怎么回事啊
你的course是个指针啊,而且指针也没赋值,&student[i].course[0].score
这个路径根本就不存在
int main()
{
struct stu
{
int number;
double score[5];
double totalscore;
};
int i;
struct stu student[4];
printf("请输入各学生学号及成绩:\n");
for(i=0;i<4;i++)
{
scanf("%d,%lf,%lf,%lf,%lf,%lf",&student[i].number,&student[i].score[0],&student[i].score[1],&student[i].score[2],&student[i].score[3],&student[i].score[4]);
printf("\n");
student[i].totalscore = student[i].score[0] + student[i].score[1] + student[i].score[2] + student[i].score[3] + student[i].score[4];
}
return 0;
}
首先student[i]是一个结构体变量,调用结构体里面的变量需要用成员运算符.,比如student[i].number,然后调用结构体里面的指针需要用成员运算符->,student[i]->course.number,建议你先学会调用再学会使用。而且std*的scanf的输出格式怎么可能是%lf,doule类型呢?