当前位置:网站首页>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;
}
边栏推荐
- C# 对象存储
- Talking about fake demand from takeout order
- AVC1与H264的区别
- 【Hot100】33. Search rotation sort array
- Could not set property 'ID' of 'class xx' with value 'XX' argument type mismatch solution
- How to choose note taking software? Comparison and evaluation of notion, flowus and WOLAI
- 一文详解ASCII码,Unicode与utf-8
- go 字符串操作
- Personal component - message prompt
- Idea set method annotation and class annotation
猜你喜欢
随机推荐
DataPipeline双料入选中国信通院2022数智化图谱、数据库发展报告
Personal component - message prompt
Clock cycle
[notes of in-depth study paper]transbtsv2: wider instead of deep transformer for medical image segmentation
"Baidu Cup" CTF competition in September, web:sql
MySQL get time
百度杯”CTF比赛 2017 二月场,Web:爆破-2
Interviewer soul torture: why does the code specification require SQL statements not to have too many joins?
关于 Notion-Like 工具的反思和畅想
49. Grouping of alphabetic ectopic words: give you a string array, please combine the alphabetic ectopic words together. You can return a list of results in any order. An alphabetic ectopic word is a
个人组件 - 消息提示
【Hot100】33. 搜索旋转排序数组
聊聊异步编程的 7 种实现方式
今年上半年,通信行业发生了哪些事?
Datapipeline was selected into the 2022 digital intelligence atlas and database development report of China Academy of communications and communications
Win10——轻量级小工具
峰会回顾|保旺达-合规和安全双驱动的数据安全整体防护体系
一文详解ASCII码,Unicode与utf-8
精彩速递|腾讯云数据库6月刊
C object storage