当前位置:网站首页>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;
}
边栏推荐
- Station B Liu Erden linear regression pytoch
- 数字经济破浪而来 ,LTD是权益独立的Web3.0网站?
- Huawei od computer test question 2
- 27io stream, byte output stream, OutputStream writes data to file
- First acquaintance with CDN
- Jushan database appears again in the gold fair to jointly build a new era of digital economy
- Vulhub vulnerability recurrence 73_ Webmin
- How to download GB files from Google cloud hard disk
- [QNX Hypervisor 2.2用户手册]6.3.3 使用共享内存(shmem)虚拟设备
- Solution of QT TCP packet sticking
猜你喜欢

Redis消息队列

网站进行服务器迁移前应做好哪些准备?

Problems encountered in installing mysql8 on MAC

Sequoiadb Lake warehouse integrated distributed database, June 2022 issue
![[force buckle]43 String multiplication](/img/fd/de63e6185af4b6293e748aaf7cee29.jpg)
[force buckle]43 String multiplication

P2802 go home

CoDeSys note 2: set coil and reset coil

How can large websites choose better virtual machine service providers?

04. Project blog log

YYGH-11-定时统计
随机推荐
Solution of QT TCP packet sticking
Li Chuang EDA learning notes 12: common PCB board layout constraint principles
Node 之 nvm 下载、安装、使用,以及node 、nrm 的相关使用
嵌入式面试题(四、常见算法)
Vulhub vulnerability recurrence 69_ Tiki Wiki
Game push: image / table /cv/nlp, multi-threaded start!
Clear floating mode
应用安全系列之三十七:日志注入
AUTOSAR from getting started to becoming proficient (10) - embedded S19 file analysis
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
Graduation design game mall
[QNX hypervisor 2.2 user manual]6.3.3 using shared memory (shmem) virtual devices
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
Note the various data set acquisition methods of jvxetable
[imgui] unity MenuItem shortcut key
B站刘二大人-数据集及数据加载 Lecture 8
Problems encountered in installing mysql8 on MAC
02. Develop data storage of blog project
First acquaintance with CDN
备忘一下jvxetable的各种数据集获取方法