废话不多说,看效果图和代码。
大概分为,密码界面和功能界面;
一共有新建,删除,修改,查询,显示所有记录,按学号排序这些功能,
并且结束程序时会保存记录到电脑文件中,下次打开时读取文件信息,实现新建信息不遗失的效果。
废话不多说,直接上代码,不懂的私信留言都可。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h>
FILE *fp;
int len = 0;
void pause(){
int i;
printf("\n\n按任意键加回车返回主菜单!");
scanf("%d",&i);
getchar();
}
struct stu
{
char name[100];//姓名为字符串型
int xh;//学号为整形
int grade;//班级
char tel[50];//电话
char add[100];//地址为字符串型
struct stu *next;//用指针处理链表,next是指针变量,指向结构体变量
};
struct stu *charu(struct stu *head,struct stu *q)
{
struct stu *p;
for(p=head;p->next!=NULL;p=p->next);//for(使p也指向head;当p为空文件时 ;p指向下一个结点)
p->next=q;
q->next=NULL;
return head;
}
void search(struct stu *head)
{
struct stu *p;
int s=0;
int a;//要查找学生的学号
if(head->next==NULL)//头文件为空时打印出的结果为"通讯录为空"
{printf("**********************************通讯录为空!!!*********************************\n\n\n");
printf("------------------------------请新建联系人后尝试!!!-----------------------------\n\n");
}
else//头文件不为空时,开始查询学生的信息
{
printf("\t输入要查询学生学号:");
scanf("%d",&a);
for(p=head->next;p->next!=NULL;p=p->next)//for(使p也指向head;当p为空文件时 ;p指向下一个结点)
{
if(p->xh==a) //如果输入的学号和某个相同,输出以下的东西。
{
printf(" 要查找的学生信息为:\n");
printf(" ★姓名:");puts(p->name);
printf("\t\t学号: ");printf("%d\n",p->xh);
printf("\t\t班级:");printf("%d\n",p->grade);
printf("\t\t电话:");puts(p->tel);
printf("\t\t地址:");puts(p->add);
printf("\t\t查找成功!!!");
printf("\n\n\n");
s+=1;
break;
}
}
if(p->xh==a&&s==0)
{
printf(" 要查找的学生信息为:\n");
printf(" ★姓名:");puts(p->name);
printf("\t班级:");printf("%d\n",p->grade);
printf("\t电话:");puts(p->tel);
printf("\t地址:");puts(p->add);
printf("\t查找成功!!!");
printf("\n\n");
}
else if(s==0){
printf("no people have found!!!\n");//如果不符合,就输出没有找到
}
}
}
struct stu *change(struct stu *head)
{
int b,a,c;
int x=0;
struct stu *p;
if(head->next==NULL)// 头文件为空时,输出通讯录为空
{
printf("**********************************通讯录为空!!!*********************************\n\n");
printf("------------------------------请新建联系人后尝试!!!-----------------------------\n\n");
}
else
{
printf("\t\t\t输入要修改学生学号:");
scanf("%d",&a);
for(p&#