当前位置:网站首页>Address book (linked list implementation)
Address book (linked list implementation)
2022-07-05 13:31:00 【Pull a lot】
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
const int max = 100;
// full name 、 Gender 、 Telephone 、 mobile phone 、 Fax 、 mailbox 、 Address
typedef struct phone
{
char name[20]; // full name
char sex[20]; // Gender
int tel; // Telephone
int fax; // Fax
char qq[100]; // mailbox
char addre[20]; // Address
}Ipa;// Give an alias to the structure that stores the address book properties
typedef struct List
{
Ipa data;
struct List *next;
}list;
list *head ;
// initialization
void inint()
{
head = (list*)malloc(sizeof(list));
head->next = NULL;
printf(" Successful initialization ");
}
// Add users
void great()
{
list *p , *t;
int n;
printf(" Please enter the number of users :\n");
scanf("%d",&n);
printf(" Please input... In turn : full name 、 Gender 、 Telephone 、 Fax 、 mailbox 、 Address \n");
for(int i = 0 ; i < n ; i++)
{
p = (list*)malloc(sizeof(list));
scanf("%s %s %d %d %s %s",p->data.name,p->data.sex,&p->data.tel,&p->data.fax,p->data.qq,p->data.addre);
//printf("%s",p->data.name);
t = head->next;
head->next = p;
p->next = t;
}
}
// Show
int display()
{
list*p;
p = head->next;
if(!p)
{
printf(" Address book is empty \n");
return 0;
}
else
{
printf(" The elements are as follows :\n");
while(p)
{
printf("%s %s %d %d %s %s\n",p->data.name,p->data.sex,p->data.tel,p->data.fax,p->data.qq,p->data.addre);
p = p->next;
}
}
return 0;
}
// lookup
void seek()
{
char name_tmpt[100];
printf(" Please enter the name you want to query :\n");
scanf("%s",name_tmpt);
list *p;
p = head->next;
int flage = 0;// 1 Indicates that the element has been found
while(p)
{
if(strcmp(name_tmpt,p->data.name) == 0)
{
printf("%s %s %d %d %s %s\n",p->data.name,p->data.sex,p->data.tel,p->data.fax,p->data.qq,p->data.addre);
flage = 1;
break;
}
p = p->next;
}
if(!flage)
printf(" No information for this contact !\n");
}
// Delete
void dele()
{
char name_tmpt[100];
printf(" Please enter the name you want to delete :\n");
scanf("%s",name_tmpt);
list *p , *par;
p = head->next;
par = head;
int flage = 0;// 1 Indicates that the element has been found
while(p)
{
if(strcmp(name_tmpt,p->data.name) == 0)
{
par->next = p->next;
free(p);
//printf("%s %s %d %d %s %s\n",p->data.name,p->data.sex,p->data.tel,p->data.fax,p->data.qq,p->data.addre);
flage = 1;
printf(" Successful operation !\n");
break;
}
else
{
par = p;// Storage p Previous node of
p = p->next;
}
}
if(!flage)
printf(" No information for this contact !\n");
}
// to update
void newdata()
{
char name_tmpt[100];
printf(" Please enter the name you want to update :\n");
scanf("%s",name_tmpt);
list *p;
p = head->next;
int flage = 0;// 1 Indicates that the element has been found
while(p)
{
if(strcmp(name_tmpt,p->data.name) == 0)
{
//printf("%s %s %d %d %s %s\n",p->data.name,p->data.sex,p->data.tel,p->data.fax,p->data.qq,p->data.addre);
printf(" Please enter new information :\n");
scanf("%s %s %d %d %s %s",p->data.name,p->data.sex,&p->data.tel,&p->data.fax,p->data.qq,p->data.addre);
printf(" Successful operation !\n");
flage = 1;
break;
}
p = p->next;
}
if(!flage)
printf(" No information for this contact !\n");
}
// menu
void menu()
{
printf("\t\t\t****************************************************\n");
printf("\t\t\t1. Initialize address book 2. Set up an address book \n");
printf("\t\t\t3. Delete Contact 4. Modify contact \n");
printf("\t\t\t5. Find contacts 6. Show contacts \n");
printf("\t\t\t7 Exit the system \n");
printf("\t\t\t****************************************************\n");
}
int main()
{
menu();
int op = 10;
while(op!= 8)
{
printf(" Please select your operation :\n");
scanf("%d",&op);
switch(op)
{
case 1 : inint();break;
case 2 : great();break;
case 3 : dele();break;
case 4 : newdata();break;
case 5 : seek();break;
case 6 : display();break;
case 7 : op = 8;break;
}
}
return 0;
}
边栏推荐
- Could not set property ‘id‘ of ‘class XX‘ with value ‘XX‘ argument type mismatch 解决办法
- UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xe6 in position 76131: invalid continuation byt
- jenkins安装
- Multi person cooperation project to see how many lines of code each person has written
- RHCSA9
- The real king of caching, Google guava is just a brother
- Sorry, we can't open xxxxx Docx, because there is a problem with the content (repackaging problem)
- Asemi rectifier bridge hd06 parameters, hd06 pictures, hd06 applications
- MySQL - database query - sort query, paging query
- “百度杯”CTF比赛 九月场,Web:SQL
猜你喜欢
Cloudcompare - point cloud slice
jenkins安装
私有地址有那些
Don't know these four caching modes, dare you say you understand caching?
STM32 reverse entry
SAE international strategic investment geometry partner
Godson 2nd generation burn PMON and reload system
Backup and restore of Android local SQLite database
TortoiseSVN使用情形、安装与使用
[深度学习论文笔记]TransBTSV2: Wider Instead of Deeper Transformer for Medical Image Segmentation
随机推荐
Shu tianmeng map × Weiyan technology - Dream map database circle of friends + 1
Interviewer soul torture: why does the code specification require SQL statements not to have too many joins?
CloudCompare——点云切片
Nantong online communication group
APICloud Studio3 WiFi真机同步和WiFi真机预览使用说明
Summary and arrangement of JPA specifications
关于 Notion-Like 工具的反思和畅想
FPGA 学习笔记:Vivado 2019.1 添加 IP MicroBlaze
go 字符串操作
峰会回顾|保旺达-合规和安全双驱动的数据安全整体防护体系
前缀、中缀、后缀表达式「建议收藏」
Shuttle INKWELL & ink components
SAE international strategic investment geometry partner
Talk about seven ways to realize asynchronous programming
山东大学暑期实训一20220620
Lb10s-asemi rectifier bridge lb10s
聊聊异步编程的 7 种实现方式
一文详解ASCII码,Unicode与utf-8
数据泄露怎么办?'华生·K'7招消灭安全威胁
内网穿透工具 netapp