当前位置:网站首页>C语言通讯录系统
C语言通讯录系统
2022-07-28 05:18:00 【c7473168】
小项目: 通讯录系统
要求:存储联系人信息:
姓名,性别,电话 char name[6]"小王"
最大存储量50人
功能要求:
1,增加联系人
2,按名字删除联系人
3,按名字修改联系人信息
4,查找联系人,按照电话或者姓名,支持模糊查找 strstr
5,显示所有联系人信息
6,退出系统
#include <stdio.h>
#include <stdlib.h>
#include <getch.h>
#include <unistd.h>
#include <string.h>
static char name[50][10]; // 姓名
static char sex[50]; // 性别
static char tel[50][12]; // 电话
static int count = 0; // 有效联系人数量
void msg_show(const char* msg,float sec)
{
printf("%s",msg);
fflush(stdout);
usleep(sec*100000);
}
// 按任意键继续
void anykey_continue(void)
{
puts("按任意键继续...");
stdin->_IO_read_ptr = stdin->_IO_read_end;
getch();
}
int menu(void)
{
system("clear");
puts("---欢迎使用哈哈通讯录---");
puts("------1,添加联系人------");
puts("------2,删除联系人------");
puts("------3,修改联系人------");
puts("------4,查找联系人------");
puts("------5,遍历联系人------");
puts("------6,退出通讯录------");
puts("------------------------");
printf("请输入指令:");
char cmd = getch();
printf("%c\n",cmd); // 回显
return cmd;
}
void add(void)
{
//printf("%s\n",__func__);
if(50 <= count)
{
puts("系统正在升级,请等待...");
return;
}
int i=0;
while(sex[i]) i++;
printf("请输入新联系人姓名,性别,电话:");
scanf("%s %c %s",name[i],&sex[i],tel[i]);
count++;
msg_show("添加成功!\n",1.5);
}
void del(void)
{
// printf("%s\n",__func__);
char key[20] = {};
printf("请输入要删除的联系人姓名:");
scanf("%s",key);
for(int i=0;i<50;i++)
{
if(sex[i] && 0 == strcmp(key,name[i]))
{
sex[i] = 0;
count--;
msg_show("删除联系人成功!\n",1.5);
return;
}
}
msg_show("查无此人,删除失败!\n",1.5);
}
void mod(void)
{
printf("%s\n",__func__);
char key[20] = {};
printf("请输入要修改的联系人姓名:");
scanf("%s",key);
for(int i=0;i<50;i++)
{
if(sex[i] && 0 == strcmp(key,name[i]))
{
printf("请重新输入联系人的姓名,性别,电话:");
scanf("%s %c %s",name[i],&sex[i],tel[i]);
msg_show("修改联系人成功!\n",1.5);
return;
}
}
msg_show("查无此人!\n",1.5);
}
void find(void)
{
printf("%s\n",__func__);
char key[20] = {};
printf("请输入要查询的关键字:");
scanf("%s",key);
for(int i=0;i<50;i++)
{
if(sex[i])
{
if(strstr(name[i],key) || strstr(tel[i],key))
{
printf("%s %s %s\n",name[i],'w'==sex[i]?"女":"男",tel[i]);
}
}
}
anykey_continue();
}
void show(void)
{
// printf("%s\n",__func__);
for(int i=0;i<50;i++)
{
if(sex[i])
{
printf("%s %s %s\n",name[i],'w'==sex[i]?"女":"男",tel[i]);
}
}
anykey_continue();
}
int main(int argc,const char* argv[])
{
for(;;)
{
//显示主界面
switch(menu())
{
case '1': add(); break;
case '2': del(); break;
case '3': mod(); break;
case '4': find(); break;
case '5': show(); break;
case '6': return 0;
}
}
}
边栏推荐
- You must configure either the server or JDBC driver (via the ‘serverTimezone)
- 框架一步一步方便使用的流程
- Image enhancement - msrcr
- Personal summary of restful interface use
- When SQL queries the list, the data is inconsistent twice, and limit is automatically added
- How Visio can quickly generate the same pattern and image matrix
- Pytorch uses hook to get feature map
- latex和word之间相互转换
- openjudge:找第一个只出现一次的字符
- Multi module packaging: package: XXX does not exist
猜你喜欢

The difference between get and post

Distillation model diagram

Writing methods of scientific research papers: add analysis and discussion in the method part to explain their contributions and differences

科研论文写作方法:在方法部分添加分析和讨论说明自己的贡献和不同

Edge calculation kubeedge+edgemash

ByteBuffer. Position throws exception illegalargumentexception

c语言:通过一个例子来认识函数栈帧的创建和销毁讲解

Long和Integer如何进行比较,为什么报错

冶金物理化学复习 --- 化学反应动力学基础

Sequence table OJ topic
随机推荐
Solve the problem that Oracle cannot use more than 1000 in statements
VMware Workstation is incompatible with device/credential guard. Disable device/credential guard
动态卷积的本质
The essence of dynamic convolution
Openjudge: patient queuing
JVM篇 笔记4:内存模型
BigDecimal 进行四舍五入 四舍六入和保留两位小数
ssm项目快速搭建项目配置文件
How Visio accurately controls the size, position and angle of graphics
Openjudge: upper and lower case letters are interchanged
restFul接口使用个人总结
(黑马)MYSQL初级-高级笔记(博主懒狗)
PyTorch 使用 MaxPool 实现图像的膨胀和腐蚀
docker 部署 mysql5.7.35
openjudge:石头剪刀布
Digital twin technology creates visual application of smart mine
openjudge:统计数字字符个数
[singleton mode] thread safety of lazy mode
冶金物理化学复习 --- 冶金反应动力学基础与多相反应动力学特征
环形链表问题