为什么用指针输出不了

#include
#define N 20
struct Student
{
int num;
char name[10];
int computer,math,english;
double average;
};
struct Student stu[N];
int main()
{
struct Student update_score(struct Student *p,int n,int score);
int i,n;
printf("please enter the number of students:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("No.%d:",i+1);
scanf("%d %s %d %d %d",&stu[i].num,stu[i].name,&stu[i].computer,&stu[i].math,&stu[i].english);
stu[i].average=(stu[i].computer+stu[i].math+stu[i].english)/3.0;
}

printf("the array is:\n");
for(i=0;i<n;i++)
    printf("%d %s %d %d %d %.2lf\n",stu[i].num,stu[i].name,stu[i].computer,stu[i].math,stu[i].english,stu[i].average);

int m,f,s;
printf("please input the number of the student that you want to update:\n");
scanf("%d",&m);
printf("please input the subject(1:computer,2:math,3:english) and the new score:\n");
scanf("%d,%d",&f,&s);

struct Student *p=&stu[m];
update_score(p,f,s);
printf("the new data is:\n");
printf("%d %s %d %d %d %.2lf\n",p->num,p->name,p->computer,p->math,p->english,p->average);
return 0;

}

struct Student update_score(struct Student *p,int n,int score)
{
if(n==1)
(*p).computer=score;
if(n==2)
(*p).math=score;
if(n==3)
(*p).english=score;
if(n!=1&&n!=2&&n!=3)
printf("error!\n");
(*p).average=((*p).computer+(*p).math+(*p).english)/3.0;
return(*p);
}

只有修改后那个分数可以

查看全部
qq_43257669
qq_43257669
2018/12/14 16:16
  • c++
  • c语言
  • 点赞
  • 收藏
  • 回答
    私信

1个回复