#include<stdio.h>
struct student {
int num;
int m,c,e;
};
int updated(struct student *p,int num, int n, int score, int course);
int main()
{
struct student s[50];
int i, n, num;
int course,score;
printf("Input the numble of students:\n");
scanf("%d",&n);
for(i = 0; i < n; i++ ){
printf("Input the information:\n");
scanf("%d%d%d%d",&s[i].num ,&s[i].c ,&s[i].e ,&s[i].m );
}
printf("Input the information of the student to be updated:\n");
scanf("%d%d%d",&num,&course,&score);
int pos = updated(s,num,n,score,course);
if(pos == -1) printf("Not found\n");
else printf("num\t m\t c\t e\n%8d%8d%8d%8d\n",s[pos].num ,s[pos].m ,s[pos].c ,s[pos].e );
return 0;
}
int updated(struct student p[], int num,int n, int score, int course)
{
int i;
for(i = 0; i < n; i++){
if(p[i].num==num) break;
}
int pos=i;
switch(course){
case 1:p[i].m=score;break;//此处不能写成p->,因为用是数组的方式访问,p就不变了,永远指向首地址
case 2:p[i].c=score;break;
case 3:p[i].e=score;break;
}
return pos;
}
07-05
2948
05-18
1854