当前位置:网站首页>通讯录(链表实现)
通讯录(链表实现)
2022-07-05 13:27:00 【拉的很多】
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
const int max = 100;
//姓名、性别、电话、手机、传真、邮箱、地址
typedef struct phone
{
char name[20]; //姓名
char sex[20]; // 性别
int tel; //电话
int fax; // 传真
char qq[100]; // 邮箱
char addre[20]; //地址
}Ipa;//给存放通讯录属性的结构体取个别名
typedef struct List
{
Ipa data;
struct List *next;
}list;
list *head ;
// 初始化
void inint()
{
head = (list*)malloc(sizeof(list));
head->next = NULL;
printf("初始化成功");
}
// 添加用户
void great()
{
list *p , *t;
int n;
printf("请输入用户人数:\n");
scanf("%d",&n);
printf("请依次输入:姓名、性别、电话、传真、邮箱、地址\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;
}
}
//显示
int display()
{
list*p;
p = head->next;
if(!p)
{
printf("通讯录为空\n");
return 0;
}
else
{
printf("元素如下:\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;
}
//查找
void seek()
{
char name_tmpt[100];
printf("请输入你要查询的姓名:\n");
scanf("%s",name_tmpt);
list *p;
p = head->next;
int flage = 0;// 1表示已经找到元素
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("没有该联系人的信息!\n");
}
// 删除
void dele()
{
char name_tmpt[100];
printf("请输入你要删除的姓名:\n");
scanf("%s",name_tmpt);
list *p , *par;
p = head->next;
par = head;
int flage = 0;// 1表示已经找到元素
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("操作成功!\n");
break;
}
else
{
par = p;//存储p的前一个节点
p = p->next;
}
}
if(!flage)
printf("没有该联系人的信息!\n");
}
// 更新
void newdata()
{
char name_tmpt[100];
printf("请输入你要更新的姓名:\n");
scanf("%s",name_tmpt);
list *p;
p = head->next;
int flage = 0;// 1表示已经找到元素
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("请输入新的信息:\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("操作成功!\n");
flage = 1;
break;
}
p = p->next;
}
if(!flage)
printf("没有该联系人的信息!\n");
}
// 菜单
void menu()
{
printf("\t\t\t****************************************************\n");
printf("\t\t\t1.初始化通讯录 2.建立通讯录\n");
printf("\t\t\t3.删除联系人 4.修改联系人\n");
printf("\t\t\t5.查找联系人 6.显示通讯录 \n");
printf("\t\t\t7 退出系统 \n");
printf("\t\t\t****************************************************\n");
}
int main()
{
menu();
int op = 10;
while(op!= 8)
{
printf("请选择你的操作:\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;
}
边栏推荐
- Binder通信过程及ServiceManager创建过程
- 4年工作经验,多线程间的5种通信方式都说不出来,你敢信?
- 从外卖点单浅谈伪需求
- Get you started with Apache pseudo static configuration
- 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
- [深度学习论文笔记]使用多模态MR成像分割脑肿瘤的HNF-Netv2
- Integer ==比较会自动拆箱 该变量不能赋值为空
- C object storage
- 量价虽降,商业银行结构性存款为何受上市公司所偏爱?
- 法国学者:最优传输理论下对抗攻击可解释性探讨
猜你喜欢
“百度杯”CTF比赛 九月场,Web:SQL
STM32 reverse entry
不知道这4种缓存模式,敢说懂缓存吗?
国际自动机工程师学会(SAE International)战略投资几何伙伴
leetcode:221. Maximum square [essence of DP state transition]
MySQL - database query - sort query, paging query
Reverse Polish notation
FPGA learning notes: vivado 2019.1 add IP MicroBlaze
Can and can FD
C# 对象存储
随机推荐
Operational research 68 | the latest impact factors in 2022 were officially released. Changes in journals in the field of rapid care
FPGA learning notes: vivado 2019.1 add IP MicroBlaze
CAN和CAN FD
Win10 - lightweight gadget
[深度学习论文笔记]使用多模态MR成像分割脑肿瘤的HNF-Netv2
百度杯”CTF比赛 2017 二月场,Web:爆破-2
ASEMI整流桥HD06参数,HD06图片,HD06应用
"Baidu Cup" CTF competition in September, web:upload
go 数组与切片
Could not set property 'ID' of 'class xx' with value 'XX' argument type mismatch solution
“百度杯”CTF比赛 九月场,Web:SQL
【MySQL 使用秘籍】一网打尽 MySQL 时间和日期类型与相关操作函数(三)
leetcode 10. Regular expression matching regular expression matching (difficult)
Resttemplate details
Solve Unicode decodeerror: 'GBK' codec can't decode byte 0xa2 in position 107
What is a network port
Cloudcompare - point cloud slice
Binder communication process and servicemanager creation process
南理工在线交流群
CloudCompare——点云切片