当前位置:网站首页>Implementation of linked list in address book management system
Implementation of linked list in address book management system
2022-07-06 05:44:00 【Write poetry by programming】
This program uses a linked list to realize the management of address book information. The main operations are Delete Change check Show all information Exit six functions . Code comments are logical, easy to understand, suitable for beginners to learn linked lists .
The code is as follows :
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct stu{
char name[20];// full name
int phone;// Telephone
int telephone;// Mobile phone
int youbian;// Zip code
char tongxun[20];// Mailing address information
}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. Input information 2. find information 3. Delete the information *\n");
printf("\t\t\t\t* *\n");
printf("\t\t\t\t*4. Modify the information 5. display information 6. Exit procedure *\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(" Please enter a name \n");
scanf("%s",nam);
while(p->next!=NULL){
if(strcmp(p->date.name,nam)==0){
printf(" The student already exists \n");
break;
}
p=p->next;
}
if(p->next==NULL){
strcpy(q->date.name,nam);
printf(" Please input the phone number \n");
scanf("%d",&q->date.phone);
printf(" Please enter your mobile phone \n");
scanf("%d",&q->date.telephone);
printf(" Please enter zip code \n");
scanf("%d",&q->date.youbian);
printf(" Please enter the address information \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(" No data at this time ");
return;
}
else {
printf(" Please enter the name of the student you want to delete ");
scanf("%s",name3);
while(q!=NULL) {
if(strcmp(q->date.name,name3)==0){
p->next=q->next;
free(q);
printf(" Delete successful !\n");
}
p=q;
q=q->next;
}
}
}
void seek( linklist *head) {
int k=0;
char name3[20];
printf(" Please enter the student's name :\n");
scanf("%s",name3);
linklist *p;
p=(linklist*)malloc(sizeof(linklist));
p=head->next;
if(p==NULL){
printf("\t\t\t\t\t No information has been entered !!!\n");
}
while(p!=NULL){
if(strcmp(name3,p->date.name)==0) {
k=k+1;
printf(" full name :%s Telephone :%d Mobile phone :%d Zip code :%d Mailing address information :%s\n",p->date.name,p->date.phone,p->date.telephone,p->date.youbian,p->date.tongxun);
}
p=p->next;
}
if(k==0){
printf(" Check no one ");
}
}
void change(linklist *head){
char name4[20];
printf(" Please enter the student's name :\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(" Before the change :\n");
printf(" full name :%s Telephone :%d Mobile phone :%d Zip code :%d Mailing address information :%s\n",p->date.name,p->date.phone,p->date.telephone,p->date.youbian,p->date.tongxun);
}
p=p->next;
}
if(k==0){
printf(" Check no one \n");
}
p=head->next;
while(p!=NULL){
if(strcmp(name4,p->date.name)==0){
printf(" Please enter the number of mobile phones to be modified ");
scanf("%d",&p->date.telephone);
printf(" After modification :\n");
printf(" full name :%s Telephone :%d Mobile phone :%d Zip code :%d Mailing address information :%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(" full name :%s Telephone :%d Mobile phone :%d Zip code :%d Mailing address information :%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 Whether to continue to add (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 Welcome to the search interface , Please complete the operation as required |(@@)|\n");
seek(head);
printf("\n\n\t\t\t\t\t\t Continue to find (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 Do you want to continue deleting (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(" Exit please enter 0:");
int sel6;
scanf("%d",&sel6);
if(sel6==0) break;
default:
printf("\n Thank you for using !\n");
return 0;
}
}
return 0;
}
边栏推荐
- [Jiudu OJ 07] folding basket
- Game push: image / table /cv/nlp, multi-threaded start!
- Station B, Master Liu Er - dataset and data loading
- Improve jpopup to realize dynamic control disable
- Note the various data set acquisition methods of jvxetable
- 清除浮动的方式
- Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
- 网站进行服务器迁移前应做好哪些准备?
- Graduation design game mall
- 进程和线程
猜你喜欢
应用安全系列之三十七:日志注入
B站刘二大人-线性回归 Pytorch
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
59. Spiral matrix
ArcGIS应用基础4 专题图的制作
P2802 回家
PDK工艺库安装-CSMC
巨杉数据库再次亮相金交会,共建数字经济新时代
Mysql database master-slave cluster construction
B站刘二大人-反向传播
随机推荐
Classes and objects (I) detailed explanation of this pointer
Auto.js学习笔记17:基础监听事件和UI简单的点击事件操作
Vulhub vulnerability recurrence 68_ ThinkPHP
Station B, Master Liu Er - back propagation
Problems encountered in installing mysql8 on MAC
Codeless June event 2022 codeless Explorer conference will be held soon; AI enhanced codeless tool launched
Web Security (V) what is a session? Why do I need a session?
Vulhub vulnerability recurrence 72_ uWSGI
巨杉数据库再次亮相金交会,共建数字经济新时代
应用安全系列之三十七:日志注入
HAC cluster modifying administrator user password
What impact will frequent job hopping have on your career?
什么是独立IP,独立IP主机怎么样?
[detailed explanation of Huawei machine test] check whether there is a digital combination that meets the conditions
RustDesk 搭建一个自己的远程桌面中继服务器
Analysis of grammar elements in turtle Library
YYGH-11-定时统计
29io stream, byte output stream continue write line feed
05. 博客项目之安全
P2802 回家