当前位置:网站首页>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;
}
边栏推荐
- 04. 项目博客之日志
- 清除浮动的方式
- [Jiudu OJ 08] simple search x
- Huawei od computer test question 2
- Auto.js学习笔记17:基础监听事件和UI简单的点击事件操作
- Qt TCP 分包粘包的解决方法
- B站刘二大人-反向传播
- [imgui] unity MenuItem shortcut key
- [experience] when ultralso makes a startup disk, there is an error: the disk / image capacity is too small
- Migrate Infones to stm32
猜你喜欢
B站刘二大人-反向传播
02. 开发博客项目之数据存储
P2802 回家
应用安全系列之三十七:日志注入
P2802 go home
(column 22) typical column questions of C language: delete the specified letters in the string.
[Jiudu OJ 07] folding basket
【torch】|torch. nn. utils. clip_ grad_ norm_
[Jiudu OJ 08] simple search x
Installation de la Bibliothèque de processus PDK - csmc
随机推荐
Zoom and pan image in Photoshop 2022
PDK process library installation -csmc
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
Improve jpopup to realize dynamic control disable
[string] palindrome string of codeup
B站刘二大人-Softmx分类器及MNIST实现-Lecture 9
应用安全系列之三十七:日志注入
Migrate Infones to stm32
Winter 2021 pat class B problem solution (C language)
Self built DNS server, the client opens the web page slowly, the solution
28io stream, byte output stream writes multiple bytes
Web Security (VI) the use of session and the difference between session and cookie
Pay attention to the details of pytoch code, and it is easy to make mistakes
LeetCode_字符串反转_简单_557. 反转字符串中的单词 III
Redis message queue
Easy to understand IIC protocol explanation
Algorithm -- climbing stairs (kotlin)
59. Spiral matrix
入侵检测领域数据集总结
YYGH-11-定时统计