当前位置:网站首页>通讯录(链表实现)
通讯录(链表实现)
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;
} 边栏推荐
- Talk about seven ways to realize asynchronous programming
- MSTP and eth trunk
- Don't know these four caching modes, dare you say you understand caching?
- 龙芯派2代烧写PMON和重装系统
- Integer ==比较会自动拆箱 该变量不能赋值为空
- Matlab paper chart standard format output (dry goods)
- Clock cycle
- Solve Unicode decodeerror: 'GBK' codec can't decode byte 0xa2 in position 107
- Fragmented knowledge management tool memos
- TortoiseSVN使用情形、安装与使用
猜你喜欢

Could not set property 'ID' of 'class xx' with value 'XX' argument type mismatch solution

Huawei push service content, read notes

MySQL --- 数据库查询 - 排序查询、分页查询

Idea设置方法注释和类注释

数据湖(七):Iceberg概念及回顾什么是数据湖

go 数组与切片

量价虽降,商业银行结构性存款为何受上市公司所偏爱?

UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xe6 in position 76131: invalid continuation byt

Although the volume and price fall, why are the structural deposits of commercial banks favored by listed companies?

不知道这4种缓存模式,敢说懂缓存吗?
随机推荐
[notes of in-depth study paper]uctransnet: rethink the jumping connection in u-net from the perspective of transformer channel
There is no monitoring and no operation and maintenance. The following is the commonly used script monitoring in monitoring
Realize the addition of all numbers between 1 and number
Go array and slice
UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xe6 in position 76131: invalid continuation byt
"Baidu Cup" CTF competition in September, web:upload
49. 字母异位词分组:给你一个字符串数组,请你将 字母异位词 组合在一起。可以按任意顺序返回结果列表。 字母异位词 是由重新排列源单词的字母得到的一个新单词,所有源单词中的字母通常恰好只用一次。
Alibaba cloud SLB load balancing product basic concept and purchase process
Word document injection (tracking word documents) incomplete
Asemi rectifier bridge hd06 parameters, hd06 pictures, hd06 applications
"Baidu Cup" CTF competition in September, web:sql
Hundred days to complete the open source task of the domestic database opengauss -- openguass minimalist version 3.0.0 installation tutorial
Go string operation
What are the private addresses
Reverse Polish notation
一网打尽异步神器CompletableFuture
MMSeg——Mutli-view时序数据检查与可视化
ASEMI整流桥HD06参数,HD06图片,HD06应用
Yyds dry goods inventory # solve the real problem of famous enterprises: move the round table
Changing JS code has no effect