当前位置:网站首页>c语言结构体、函数以及指针练习(简单通讯录)
c语言结构体、函数以及指针练习(简单通讯录)
2022-08-09 23:42:00 【BSP初级小学僧】
#include <stdio.h>
#include <string.h>
typedef struct
{
char name[20];
long long phone;
char sex[10];
char dress[20];
int age;
}Person;
Person person_arr[20]={
{"熊大",10086,"男","河南",24},
{"熊二",10010,"男","陕西",23},
{"熊三",911,"男","湖北",25}};
void add()
{
int i,n;
printf("请输入本次需要添加几位通讯录好友:\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("请输入要添加的好友信息,名字 电话 性别 地址 年龄\n");
scanf("%s %lld %s %s %d", &person_arr[i+3].name,&person_arr[i+3].phone,\
&person_arr[i+3].sex,&person_arr[i+3].dress,&person_arr[i+3].age);
}
}
void del()
{
int i;
char name[20];
Person temp={0};
printf("请输入要删除的好友名字\n");
scanf("%s",name);
for(i=0;i<20;i++)
{
if(strcmp(person_arr[i].name,name)==0)
person_arr[i]=temp;
}
}
void seek()
{
int i;
char name[20];
printf("请输入要搜索的好友名字\n");
scanf("%s",name);
for(i=0;i<20;i++)
{
if(strcmp(person_arr[i].name,name)==0)
printf("%s %lld %s %s %d\n",person_arr[i].name,person_arr[i].phone,\
person_arr[i].sex,person_arr[i].dress,person_arr[i].age);
}
}
void modify()
{
int i;
char name[20];
printf("请输入要修改的好友名字\n");
scanf("%s",name);
for(i=0;i<20;i++)
{
if(strcmp(person_arr[i].name,name)==0)
{
printf("请输入要修改的好友信息, 名字 电话 性别 地址 年龄\n");
scanf("%s %lld %s %s %d", person_arr[i].name,&person_arr[i].phone,\
person_arr[i].sex,person_arr[i].dress,&person_arr[i].age);
}
}
}
void print()
{
int i;
Person temp={0};
for(i=0;i<20;i++)
{
if(person_arr[i].phone != 0)
{
printf("名字: %s 电话: %lld 性别: %s 地址: %s 年龄: %d\n",\
person_arr[i].name,person_arr[i].phone,person_arr[i].sex,\
person_arr[i].dress,person_arr[i].age);
}
}
}
void classfy()
{
Person temp;
int i,j;
for(i=0;i<19;i++)
{
for(j=0;j<19-i;j++)
{
//if(strcmp(person_arr[j].name,person_arr[j+1].name)==1)
if(person_arr[j].age>person_arr[j+1].age)
{
temp=person_arr[j];
person_arr[j]=person_arr[j+1];
person_arr[j+1]=temp;
}
}
}
}
int main()
{
int n=100;
while(n != 0)
{
printf("本通讯录名单信息如下:\n");
print();
printf("功能如下:\n");
printf("1、增加好友 2、删除好友\n");
printf("3、搜索好友 4、修改好友\n");
printf("5、打印好友 6、通讯录排序\n");
printf("0、退出\n");
scanf("%d", &n);
switch(n)
{
case 1:
add();
break;
case 2:
del();
break;
case 3:
seek();
break;
case 4:
modify();
break;
case 5:
print();
break;
case 6:
classfy();
break;
default :
break;
}
}
return 0;
}
运行结果:
边栏推荐
- MATLB|And her ups and downs and finally reached the peak of life [Romantic Journey]
- 考柏的感慨
- ETCD快速入门-02 ETCD安装
- 《MySQL入门很轻松》第4章:数据表中存放的数据类型
- abicc 知:API compatibility report 介绍
- The older tester has just passed the "hurdle" of being 35 years old, and I want to tell you something from my heart
- 蔚来杯2022牛客暑期多校训练营7 CFGJ
- Leetcode83. 删除排序链表中的重复元素
- Leetcode80. 删除有序数组中的重复项 II
- 为什么不建议你在 Docker 中跑 Mysql ?
猜你喜欢
Web性能测试模型小结
Golden Warehouse Database KingbaseGIS User Manual (6.4. Geometry Object Access Function)
上交所实时行情文件汇总
Leecode-205. 同构字符串
pytest:如何在测试中编写和报告断言
【云原生】Kubernetes编排工具精讲
【数据存储】signed,unsigned到底怎么区分?如何计算?
ES6 Beginner to Mastery #13: Extension Methods for Arrays 2
MATLB|和她跌宕起伏最终到达人生之峰【浪漫旅途】
CST Studio Suite 2021 software installation package and installation tutorial
随机推荐
Redis redisTemplate.execute 执行锁
错误提示:Syntax error on token “function”, delete this token
Web性能测试模型小结
Koa中间件next实现
Eureka protects itself
【Django】缓存
Leetcode82. 删除排序链表中的重复元素 II
20220808-一些想法
Pinduoduo store operation must know to leave a little knowledge of operation
Redis-基本介绍/linux下环境配置/配置文件
数字钱包红海角逐,小程序生态快速引入可助力占领智慧设备入口
pytest:如何在测试中编写和报告断言
算法---整数替换(Kotlin)
The older tester has just passed the "hurdle" of being 35 years old, and I want to tell you something from my heart
New window Display Agreement
[C language] Address book "Static Memory Version"
LSTM-based distributed energy generation prediction (Matlab code implementation)
Description of AirFlow
Alibaba Cloud SMS Service Activation
收银管理软件如何做好员工管理?