if 语句失效

0

使用结构体编程,要输入一个学生的学号,显示出这个学生的信息,运行出来以后所有学生的信息都显示了,不知道哪出问题了

#include<stdio.h>
#define N 10
struct student
{
	long number;
	char name[20],sex;
	float score[3],average;
};
int main(void)
{
	struct student stu[N];
	long xuehao;
	int i,l=-1;
	printf("请按如下顺序输入第%d名学生的信息:\n",N);
    printf("学号姓名性别成绩1成绩2成绩3\n");
	for(i=0;i<N;i++)
	{
		printf("请输入第%d名学生的信息:\n",i+1);
		scanf("%ld%s%*c%c%*c%f%f%f",&stu[i].number,
			&stu[i].name,&stu[i].sex,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);}
	for(i=0;i<N;i++)
		stu[i].average=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3;
	printf("请输入学号:");
	scanf("%ld",&xuehao);
	for(i=0;i<N;i++)
	{
		if(xuehao=stu[i].number)
			l=i+1;
		else l=0;
		if(l!=0)
			printf("该学生信息为:%ld%s%*c%c%*c%f%f%f",stu[i].number,
				stu[i].name,stu[i].sex,stu[i].score[0],stu[i].score[1],stu[i].score[2]);
		else printf("wrong\n");
	}
	
	return 0;
}
ava
月悬忘川口

2020-12-8

0

这里错了:

if(xuehao=stu[i].number)

这是赋值,不是比较。应该用 ==

ava
慢羊羊

2020-12-8

技术讨论社区
相关提问