为啥函数接收不到数据啊
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 10
struct Student
{
char name[20];
float score[3];
}stu[3];
void Display(struct Student *a)
{
printf("----信息如下----\n");
printf("姓名:%s\n", a->name);
printf("语文:%.2f\n", a->score[0]);
printf("数学:%.2f\n", a->score[1]);
printf("英语:%.2f\n", a->score[2]);
printf("平均成绩:%.2f", (a->score[0] + a->score[1] + a->score[2]) / 3);
}
int main()
{
int i;
struct Student *p;
p = &stu[0];
for (i = 0; i<3; i++, p++)
{
printf("姓名:");
scanf("%s", &stu[i].name);
printf("\n");
printf("语文:");
scanf("%f", &stu[i].score[0]);
printf("\n");
printf("数学:");
scanf("%f", &stu[i].score[1]);
printf("\n");
printf("英语:");
scanf("%f",& stu[i].score[2]);
}
for (i = 0; i<3; i++, p++)
{
Display(p);
}
system("pause");
return 0;
}
``
```c
void Display(struct Student a[],int i)
{
printf("----信息如下----\n");
printf("姓名:%s\n",a[i].name);
printf("语文:%.2f\n",a[i].score[0]);
printf("数学:%.2f\n",a[i].score[1]);
printf("英语:%.2f\n",a[i].score[2]);
printf("平均成绩:%.2f",(a[i].score[0]+a[i].score[1]+a[i].score[2])/3);
}
为啥指针传参不对,去掉指针就可以了下面是改的