当前位置:网站首页>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;
}
边栏推荐
- Detailed summary of SQL injection
- Closure, decorator
- B站刘二大人-反向传播
- How to get list length
- 移植InfoNES到STM32
- [detailed explanation of Huawei machine test] statistics of shooting competition results
- Redis message queue
- Game push image / table /cv/nlp, multi-threaded start
- Station B, Mr. Liu Er - multiple logistic regression, structure 7
- js Array 列表 实战使用总结
猜你喜欢
B站刘二大人-数据集及数据加载 Lecture 8
RustDesk 搭建一个自己的远程桌面中继服务器
Graduation design game mall
What preparations should be made for website server migration?
[SQL Server Express Way] - authentification et création et gestion de comptes utilisateurs
Zoom and pan image in Photoshop 2022
How can large websites choose better virtual machine service providers?
B站刘二大人-线性回归 Pytorch
Yygh-11-timing statistics
Garbage collector with serial, throughput priority and response time priority
随机推荐
移植InfoNES到STM32
01. Project introduction of blog development project
Promotion hung up! The leader said it wasn't my poor skills
实践分享:如何安全快速地从 Centos迁移到openEuler
Clear floating mode
Garbage collector with serial, throughput priority and response time priority
[string] palindrome string of codeup
改善Jpopup以实现动态控制disable
P2802 go home
Web Security (VI) the use of session and the difference between session and cookie
Game push image / table /cv/nlp, multi-threaded start
[Tang Laoshi] C -- encapsulation: classes and objects
02. 开发博客项目之数据存储
Rustdesk builds its own remote desktop relay server
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
[force buckle]43 String multiplication
数字经济破浪而来 ,LTD是权益独立的Web3.0网站?
PDK工藝庫安裝-CSMC
28io stream, byte output stream writes multiple bytes
01. 开发博客项目之项目介绍