|

楼主 |
发表于 2021-12-25 12:11:56
|
显示全部楼层
这是我的代码
- #include <stdio.h>
- struct Date
- {
- int year;
- int month;
- int day;
- };
- struct Student
- {
- int id;
- char name[4];
- struct Date birthdayDate;
- struct Student *next;
- };
- int main(void)
- {
- int i, j, n;
- struct Student *headStu;
-
- struct Student stu[40];
-
- printf("要插入的多少位学生信息(位):");
- scanf("%d",&j);
-
- for (i = 1; i <= j; i++)
- {
- printf("请录入第 %d个学生的数据....\n",i);
-
- printf("请输入学生ID:");
- scanf("%d",&stu[j].id);
-
- printf("请输入学生的姓名:");
- scanf("%s",stu[j].name);
-
- printf("请输入学生的出生日期(yyyy-yy-yy):");
- scanf("%d-%d-%d",&stu[j].birthdayDate.year,&stu[j].birthdayDate.month,&stu[j].birthdayDate.day);
-
- printf("\n");
- }
- printf("请输入你需要查询的学生学号:");
- scanf("%d",n);
-
- searth(*headStu, n);
-
- return 0;
- }
- int searth(struct Student *head, int n)//代入head的实参是结构体链表头指针
- {
- while(head)
- {
- if(head->id == n)
- {
- printf("学号:%d\n 姓名:%s\n",head->id,head->name);
- printf("出生日期:%d年%d月%d日",head->birthdayDate.year,head->birthdayDate.month,head->birthdayDate.day);
- return 1;
- }
- head = head -> next;
- }
- printf("没找到。");
- return 0;
- }
复制代码
为什么查询时学号输入对了,但还是输出没找到呢?
|
|