当前位置:网站首页>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;
}
边栏推荐
- How to get list length
- C进阶-数据的存储(上)
- 【经验】win11上安装visio
- A master in the field of software architecture -- Reading Notes of the beauty of Architecture
- Station B, Mr. Liu Er - multiple logistic regression, structure 7
- 毕业设计游戏商城
- Zoom through the mouse wheel
- [QNX Hypervisor 2.2用户手册]6.3.3 使用共享内存(shmem)虚拟设备
- Vulhub vulnerability recurrence 72_ uWSGI
- 03. 开发博客项目之登录
猜你喜欢

Vulhub vulnerability recurrence 67_ Supervisor

ARTS Week 25

Station B Liu Erden linear regression pytoch

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

类和对象(一)this指针详解

03. 开发博客项目之登录

Mysql database master-slave cluster construction

数字经济破浪而来 ,LTD是权益独立的Web3.0网站?

Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist

Self built DNS server, the client opens the web page slowly, the solution
随机推荐
Web Security (VI) the use of session and the difference between session and cookie
LeetCode_字符串反转_简单_557. 反转字符串中的单词 III
[machine learning notes] univariate linear regression principle, formula and code implementation
03. 开发博客项目之登录
[Jiudu OJ 08] simple search x
27io stream, byte output stream, OutputStream writes data to file
[SQL Server Express Way] - authentification et création et gestion de comptes utilisateurs
Zoom through the mouse wheel
Mysql database master-slave cluster construction
Luogu [Beginner Level 4] array p1427 number game of small fish
Vulhub vulnerability recurrence 69_ Tiki Wiki
Station B, Master Liu Er - back propagation
PDK process library installation -csmc
Report on market depth analysis and future trend prediction of China's arsenic trioxide industry from 2022 to 2028
(column 22) typical column questions of C language: delete the specified letters in the string.
Migrate Infones to stm32
JS array list actual use summary
04. 项目博客之日志
Embedded interview questions (I: process and thread)
28io stream, byte output stream writes multiple bytes