【*易错】数组名a是地址常量

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值