当前位置:网站首页>通讯录管理系统链表实现
通讯录管理系统链表实现
2022-07-06 05:39:00 【用编程写诗】
本程序采用链表的方式可以实现对于通讯录信息的管理操作主要有增 删 改 查 显示全部信息 退出六个功能。代码注释都有逻辑简单易懂适合初学者进行链表的学习。
代码如下:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct stu{
char name[20];//姓名
int phone;//电话
int telephone;//移动电话
int youbian;//邮编
char tongxun[20];//通讯地址信息
}stu;
typedef struct linklist{
stu date;
struct linklist *next;
}linklist;
struct linklist* head=NULL;
struct linklist* tail=NULL;
void menu(){
system("cls");
printf("\t\t\t\t***************************************************\n");
printf("\t\t\t\t* *\n");
printf("\t\t\t\t*1.录入信息 2.查找信息 3.删除信息 *\n");
printf("\t\t\t\t* *\n");
printf("\t\t\t\t*4.修改信息 5.显示信息 6.退出程序 *\n");
printf("\t\t\t\t***************************************************\n");
}
void add(linklist *head){
linklist *q=(linklist*)malloc(sizeof(linklist));
q->next=NULL;
linklist *p;
p=head;
char nam[20];
printf(" 请输入姓名 \n");
scanf("%s",nam);
while(p->next!=NULL){
if(strcmp(p->date.name,nam)==0){
printf("该学生已存在\n");
break;
}
p=p->next;
}
if(p->next==NULL){
strcpy(q->date.name,nam);
printf(" 请输入电话 \n");
scanf("%d",&q->date.phone);
printf(" 请输入移动电话 \n");
scanf("%d",&q->date.telephone);
printf(" 请输入邮编 \n");
scanf("%d",&q->date.youbian);
printf(" 请输入通讯地址信息 \n");
scanf("%s",&q->date.tongxun);
p->next=q;
p=q;
}
}
void delet(linklist *head) {
linklist *p,*q;
p=(linklist*)malloc(sizeof(linklist));
q=(linklist*)malloc(sizeof(linklist));
p=head;
q=p->next;
char name3[20];
if(p==NULL) {
printf("此时无数据");
return;
}
else {
printf("请输入你想删除的学生的名字");
scanf("%s",name3);
while(q!=NULL) {
if(strcmp(q->date.name,name3)==0){
p->next=q->next;
free(q);
printf("删除成功!\n");
}
p=q;
q=q->next;
}
}
}
void seek( linklist *head) {
int k=0;
char name3[20];
printf("请输入学生姓名:\n");
scanf("%s",name3);
linklist *p;
p=(linklist*)malloc(sizeof(linklist));
p=head->next;
if(p==NULL){
printf("\t\t\t\t\t还未录入信息!!!\n");
}
while(p!=NULL){
if(strcmp(name3,p->date.name)==0) {
k=k+1;
printf("姓名:%s 电话:%d 移动电话:%d 邮编:%d 通讯地址信息:%s\n",p->date.name,p->date.phone,p->date.telephone,p->date.youbian,p->date.tongxun);
}
p=p->next;
}
if(k==0){
printf("查无此人");
}
}
void change(linklist *head){
char name4[20];
printf("请输入学生姓名:\n");
scanf("%s",name4);
int k=0;
linklist *p;
p=(linklist*)malloc(sizeof(linklist));
p=head->next;
while(p!=NULL){
if(strcmp(name4,p->date.name)==0) {
k=1;
printf("修改前:\n");
printf("姓名:%s 电话:%d 移动电话:%d 邮编:%d 通讯地址信息:%s\n",p->date.name,p->date.phone,p->date.telephone,p->date.youbian,p->date.tongxun);
}
p=p->next;
}
if(k==0){
printf("查无此人\n");
}
p=head->next;
while(p!=NULL){
if(strcmp(name4,p->date.name)==0){
printf("请输入移动电话要修改成多少");
scanf("%d",&p->date.telephone);
printf("修改后:\n");
printf("姓名:%s 电话:%d 移动电话:%d 邮编:%d 通讯地址信息:%s\n",p->date.name,p->date.phone,p->date.telephone,p->date.youbian,p->date.tongxun);
break;
}
}
p=p->next;
}
void print(linklist *head){
linklist *p;
p=(linklist*)malloc(sizeof(linklist));
p=head->next;
while(p!=NULL){
printf("姓名:%s 电话:%d 移动电话:%d 邮编:%d 通讯地址信息:%s\n",p->date.name,p->date.phone,p->date.telephone,p->date.youbian,p->date.tongxun);
p=p->next;
}
}
int main()
{
int choose;
head=(linklist*)malloc(sizeof(linklist));
head->next=NULL;
while(1){
menu();
scanf("%d",&choose);
switch(choose){
case 1:
do{
system("cls");
add(head);
char sel[5];
printf("\t\t\t\t\t\t是否继续添加(yes or no): ");
scanf("%s",sel);
if(strcmp(sel,"yes")==0) continue;
else break;
}while(1);
break;
case 2:
do{
printf("\t\t\t\t欢迎来到查找界面,请按要求完成操作|(@@)|\n");
seek(head);
printf("\n\n\t\t\t\t\t\t是否继续查找(yes or no):");
char sel2[5];
scanf("%s",sel2);
if(strcmp(sel2,"yes")==0) continue;
else break;
}while(1);
break;
case 3:
do{
delet(head);
char sel3[5];
printf("\t\t\t\t是否继续删除(yes or no): ");
scanf("%s",sel3);
if(strcmp(sel3,"yes")==0) continue;
else break;
}while(1);
break;
case 4:
change(head);
break;
case 5:
system("cls");
print(head);
printf("退出请输入0:");
int sel6;
scanf("%d",&sel6);
if(sel6==0) break;
default:
printf("\n感谢使用!\n");
return 0;
}
}
return 0;
}
边栏推荐
- B站刘二大人-Softmx分类器及MNIST实现-Lecture 9
- JDBC calls the stored procedure with call and reports an error
- [untitled]
- 03. 开发博客项目之登录
- UCF (summer team competition II)
- 02. 开发博客项目之数据存储
- Redis message queue
- [machine learning notes] univariate linear regression principle, formula and code implementation
- [imgui] unity MenuItem shortcut key
- After the project is released, index Html is cached
猜你喜欢
SequoiaDB湖仓一体分布式数据库2022.6月刊
Redis message queue
What impact will frequent job hopping have on your career?
The digital economy has broken through the waves. Is Ltd a Web3.0 website with independent rights and interests?
初识CDN
Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
What preparations should be made for website server migration?
Sword finger offer II 039 Maximum rectangular area of histogram
C进阶-数据的存储(上)
[force buckle]43 String multiplication
随机推荐
[cloud native] 3.1 kubernetes platform installation kubespher
03. 开发博客项目之登录
01. Project introduction of blog development project
04. Project blog log
【torch】|torch. nn. utils. clip_ grad_ norm_
Jushan database appears again in the gold fair to jointly build a new era of digital economy
[experience] install Visio on win11
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Deep learning -yolov5 introduction to actual combat click data set training
Auto.js学习笔记17:基础监听事件和UI简单的点击事件操作
Codeless June event 2022 codeless Explorer conference will be held soon; AI enhanced codeless tool launched
Node 之 nvm 下载、安装、使用,以及node 、nrm 的相关使用
Sequoiadb Lake warehouse integrated distributed database, June 2022 issue
Questions d'examen écrit classiques du pointeur
MySQL advanced learning summary 9: create index, delete index, descending index, and hide index
[QNX hypervisor 2.2 user manual]6.3.3 using shared memory (shmem) virtual devices
05. 博客项目之安全
Unity Vector3. Use and calculation principle of reflect
注释、接续、转义等符号
【SQL server速成之路】——身份驗證及建立和管理用戶賬戶