当前位置:网站首页>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;
}
}
}
边栏推荐
猜你喜欢

Digital twin solutions inject new momentum into the construction of chemical parks

JUC notes

VMware Workstation is incompatible with device/credential guard. Disable device/credential guard

链表中关于快慢指针的oj题

多模块打包:程序包:xxx不存在

Thesis writing function words

MySQL adds sequence number to query results

Delete specific elements in order table OJ

冶金物理化学复习 --- 复杂反应的速率方程

冶金物理化学复习 --- 冶金反应动力学基础与多相反应动力学特征
随机推荐
(黑马)MYSQL初级-高级笔记(博主懒狗)
The essence of dynamic convolution
Openjudge: count the number of numeric characters
The Monte Carlo method solves the PI and draws points with turtle, and completes the progress bar problem
mysql中使用list作为参数进行查询
BigDecimal rounds and retains two decimal places
openjudge:判断字符串是否为回文
ECCV22 最新54篇论文主图整理
ssm项目快速搭建项目配置文件
图像增强评价指标学习之——结构相似性SSIM
Review of metallurgical physical chemistry ---- gas solid reaction kinetics
关于swagger中的localDateTime
蒸馏模型图
Openjudge: find the first character that appears only once
深度学习医学图像模型复现
深度学习热力图可视化的方式
docker 部署 mysql5.7.35
Arrangement of main drawings of the latest 54 papers of eccv22
集合框架的操作使用
Learning of image enhancement evaluation index -- structural similarity SSIM