在chaxun 这一块一直报错,xuehao被破坏
#include
#include
#define MAX 100
typedef struct student
{
char xuehao;
char name[20];
double yuwen;
double math;
};
typedef struct
{
student student[MAX];
int length;
}seqlist;
seqlist luru(seqlist* L)
{
int n;
printf_s("请输入学生人数\n");
scanf_s("%d", &n);
L->length = n;
printf_s("请按照学号、姓名、语文成绩、数学成绩的顺序输入\n");
for (int i = 0; i < n; i++)
{
getchar();
scanf_s("%s", &L->student[i].xuehao,50);
scanf_s("%s", &L->student[i].name,50);
scanf_s("%lf", &L->student[i].yuwen);
scanf_s("%lf", &L->student[i].math);
}
return *L;
}
int chaxun(seqlist* L)
{
int n = L->length;
char xuehao_1;
printf_s("请输入想查询学生的学号\n");
scanf_s("%s", &xuehao_1,50);
for(int i=0;iif (xuehao_1 == L->student[i].xuehao)
{
printf_s("%s\n", L->student[i].name);
printf_s("%.1lf\n", L->student[i].math);
printf_s("%.1lf\n", L->student[i].yuwen);
return 1;
}
printf("请查询正确后重试\n");
return NULL;
}
void tongji(seqlist *L)
{
double sum_1=0, sum_2=0;
for (int i=0; i < L->length; i++)
sum_1 = sum_1+L->student[i].math;
printf_s("数学成绩平均分为 %.1lf\n",sum_1 / L->length);
for (int i=0; i < L->length; i++)
sum_2 = sum_2+L->student[i].yuwen;
printf_s("数学成绩平均分为 %.1lf\n",sum_2 / L->length);
}
int menu_select()
{
int i;
printf_s("1.录入\n");
printf_s("2.查询\n");
printf_s("3.统计\n");
printf_s("4.退出\n");
do
{
scanf_s("%d",&i);
return i;
} while (i < 5 && i>0);
}
int main()
{
seqlist* L;
L = (seqlist*)malloc(sizeof(seqlist));
for (;;)
{
switch (menu_select())
{
case 1:
luru(L);
break;
case 2:
chaxun(L);
break;
case 3:
tongji(L);
break;
case 4:
exit ;
}
}
}
typedef struct student
{
char xuehao[50];
char name[50];
double yuwen;
double math;
}
int chaxun(seqlist* L)
{
int n = L->length;
char xuehao_1[50];
printf_s("请输入想查询学生的学号\n");
scanf_s("%s", &xuehao_1,50);
for(int i=0;i<n;i++)
if (strcmp(xuehao_1, L->student[i].xuehao) == 0)
{
printf_s("%s\n", L->student[i].name);
printf_s("%.1lf\n", L->student[i].math);
printf_s("%.1lf\n", L->student[i].yuwen);
return 1;
}
printf("请查询正确后重试\n");
return NULL;
}