当前位置:网站首页>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;
} 边栏推荐
- 运筹说 第68期|2022年最新影响因子正式发布 快看管科领域期刊的变化
- Fragmented knowledge management tool memos
- MySQL --- 数据库查询 - 排序查询、分页查询
- "Baidu Cup" CTF competition in September, web:sql
- 【 script secret pour l'utilisation de MySQL 】 un jeu en ligne sur l'heure et le type de date de MySQL et les fonctions d'exploitation connexes (3)
- go map
- Talking about fake demand from takeout order
- [notes of in-depth study paper]uctransnet: rethink the jumping connection in u-net from the perspective of transformer channel
- 前缀、中缀、后缀表达式「建议收藏」
- 爱可生SQLe审核工具顺利完成信通院‘SQL质量管理平台分级能力’评测
猜你喜欢

Datapipeline was selected into the 2022 digital intelligence atlas and database development report of China Academy of communications and communications

Sorry, we can't open xxxxx Docx, because there is a problem with the content (repackaging problem)

Don't know these four caching modes, dare you say you understand caching?

MSTP and eth trunk

真正的缓存之王,Google Guava 只是弟弟

Idea设置方法注释和类注释

stm32逆向入门

山东大学暑期实训一20220620

Reverse Polish notation

华为推送服务内容,阅读笔记
随机推荐
Write macro with word
同事半个月都没搞懂selenium,我半个小时就给他整明白!顺手秀了一波爬淘宝的操作[通俗易懂]
js判断数组中是否存在某个元素(四种方法)
什么是网络端口
How to apply the updated fluent 3.0 to applet development
数据泄露怎么办?'华生·K'7招消灭安全威胁
数据湖(七):Iceberg概念及回顾什么是数据湖
关于 Notion-Like 工具的反思和畅想
南理工在线交流群
面试官灵魂拷问:为什么代码规范要求 SQL 语句不要过多的 join?
MySQL get time
Shu tianmeng map × Weiyan technology - Dream map database circle of friends + 1
"Baidu Cup" CTF competition in September, web:sql
APICloud Studio3 API管理与调试使用教程
Binder communication process and servicemanager creation process
今年上半年,通信行业发生了哪些事?
SAE international strategic investment geometry partner
stm32逆向入门
TortoiseSVN使用情形、安装与使用
APICloud Studio3 WiFi真机同步和WiFi真机预览使用说明