typedef struct stu_1{
char name[10];
int cj;
}STU;
void find_name(STU *mas, int longe, char *name){
int i;
for(i = 0; i < longe; i++){
if(strcmp(name, mas[i].name) == 0){
printf("%s %d \n",mas[i].name ,mas[i].cj);
}
}
}
void find_cj(STU *mas, int longe, int *cj){
int i;
for(i = 0; i < longe; i++){
if(*cj == mas[i].cj){
printf("%s %d \n",mas[i].name ,mas[i].cj);
}
}
}
int main(){
STU mas[10];
int i;
for(i = 0; i < 10; i++){
scanf("%s%d",mas[i].name ,&mas[i].cj);
}
getchar();
printf("请输入名字\n");
char n[10];
gets(n);
printf("请输入成绩\n");
int m;
scanf("%d",&m);
printf("通过名字查询\n");
find_name(mas,10,n);
printf("\n");
printf("通过成绩查询\n");
find_cj(mas,10,&m);
return 0;
}
这道题是创建了一个类型,其中成员包括(学生姓名和学生成绩),然后我们可以通过输入学生姓名和学生成绩来查询信息。
我们可以在成员部分添加很多信息,例如学号,性别,年级等信息。然后通过键盘输入成员之一的变量来进行查询学生信息。