- #include <stdio.h>
- #include <string.h>
- int main(){
- enum Gender{
- GenderMale,GenderFemale
- };
-
- struct Student
- {
- //int stuentNum;
- char *name;
- enum Gender gender;
- int age;
- int score;
-
- };
-
- //保存学生的数量
-
- #define STUNUM 100
-
- int realStuNum = 7;
-
-
- // 全部学生信息
-
- struct Student stu[STUNUM] ={
- {"Jack",GenderMale,18,75},
- {"Rose",GenderFemale,17,80},
- {"Lilei",GenderMale,20,90},
- {"Lucy",GenderFemale,23,82},
- {"MeiMei",GenderFemale,25,73},
- {"Poly",GenderMale,30,72},
- {"Ming",GenderMale,15,60}};
-
-
- /**
- * 提示用户输入姓名
- */
- printf("请输入你要查询的姓名:");
- char name[10];
- rewind(stdin);
- gets(name);
- puts(name);
- //fgets(stu.name, 20, stdin);
-
- // 遍历所有学生,查找与输入姓名相符的人并打印其信息
-
- for(int i = 0;i < realStuNum;i++)
- {
- if(strcmp(name, stu[i].name)==0)
- {
- printf("%d\t%s\t%s\t%d \t %d\n",
- i+1,
- stu[i].name,
- stu[i].gender == GenderMale?"男":"女",
- stu[i].age,
- stu[i].score);
- return 0;
-
- }
-
- }
- printf("找不到学生\n");
- }
复制代码 |