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

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

论文写作用词

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

Fusiongan code learning (I)

You must configure either the server or JDBC driver (via the ‘serverTimezone)

GET与POST区别

Redis' bloom filter

Digital twin technology creates visual application of smart mine

The Monte Carlo method solves the PI and draws points with turtle, and completes the progress bar problem

Redis 之布隆过滤器
随机推荐
Export excel, generate multiple sheet pages, and name them
Low illumination image data set
GET与POST区别
MySQL uses list as a parameter to query
2021CSDN博客之星评选,互投
Openjudge: find all substring positions
repackag failed: Unable to find main class
[MySQL] solve the problem of MySQL time zone and 8-hour difference in database time
The way of deep learning thermodynamic diagram visualization
Digital twin solutions inject new momentum into the construction of chemical parks
openjudge:判断字符串是否为回文
Simpledateformat thread unsafe and datetimeformatter thread safe
latex使用\hl进行高亮时遇到引用总是报错,显示少了括号或者多了括号
Personal summary of restful interface use
pytorch 计算模型的GFlops和total params的方法
Use of IO streams
PyTorch 使用 MaxPool 实现图像的膨胀和腐蚀
Problems encountered when the registry service Eureka switches to nocas
导出excel,生成多个sheet页,并命名
Openjudge: judge whether the string is palindrome