C语言:编写一个查找数据的功能菜单

来源:百度知道 编辑:UC知道 时间:2024/05/24 04:13:19
该功能可允许用户输入某个同学的学号,并依此学号在链表中进行查找,如果在链表中存在该同学,则打印出该同学的学号和成绩。如果链表中不存在该同学,则给出提示信息。

#include <stdio.h>
#include <stdlib.h>

typedef struct student
{
int num; //学号
int score; //成绩
struct student *next; //节点的next
}stu; //学生信息节点

void main()
{
void creat(stu *);
void select(int,stu*);
void show(stu*); //函数声明
stu *L;
int flag=1,sno;
char choice;
L=(stu*)malloc(sizeof(stu));
L->next=NULL; //初始化链表
creat(L); //创建学生信息链表
show(L); //显示链表中所有学生的信息
while(flag) //控制自动循环查找
{
printf("do you want to sele\n");
getchar(); //吸收回车符
scanf("%c",&choice);
if(choice=='y'||choice=='Y')
{
printf("input the num\n");
scanf("%d",&sno);
select(sno,L);
}