通讯录
来源:互联网 发布:网络医疗咨询平台 编辑:程序博客网 时间:2024/04/30 22:11
#include<stdio.h>#include<stdlib.h>#include<string.h>#define N 20#define MAX 10000typedef struct people{char name[N];char sex[N];int age;char call[N];char address[N];}People;typedef struct list{People *user;int user_count;}List;void AddList(List *p){int i;printf("请输入添加的组数:");scanf("%d",&p->user_count);printf("请依次输入姓名 性别 年龄 电话 地址 \n");for(i=0;i<p->user_count;i++){scanf("%s",p->user[i].name);scanf("%s%d%s",p->user[i].sex,&p->user[i].age,p->user[i].call);scanf("%s",p->user[i].address);}}int find(List *p){int i;char name[N];printf("输入姓名:");scanf("%s",name);for(i=0;i<p->user_count;i++){if(strcmp(p->user[i].name,name)==0){return i;}}return -1;}void delet(list *p){int i=0;int ret=find(p);if(ret!=-1){for(i=ret;i<p->user_count-1;i++){p->user[i]=p->user[i+1];}}else{printf("不存在\n");exit(-1);}p->user_count--;}void modify(List *p){int ret=find(p);if(ret!=-1){printf("修改姓名:");scanf("%s",p->user[ret].name);}else{printf("没有需要修改的内容\n");exit(-1);}}void clean(List *p){p->user_count=0;printf("数据已被清理\n");}void show(List *p){int i=0;printf("姓名\t\t性别\t\t年龄\t\t电话\t\t地址\n");for(i=0;i<p->user_count;i++){printf("%s\t\t%s\t\t%d\t\t%s\t\t%s\n",p->user[i].name,p->user[i].sex,p->user[i].age,p->user[i].call,p->user[i].address);}}void main(){int n=1;List *head=(List*)malloc(sizeof(List));if(head==NULL){printf("分配内存失败\n");exit(-1);}head->user=(People*)malloc(MAX*sizeof(People));if(head->user==NULL){printf("分配内存失败\n");exit(-1);}while(n){printf("请选择输入:1:添加\t2:删除\t3:修改\t4:清理\t5:显示\t0:结束程序\n");scanf("%d",&n);switch(n){case 1: AddList(head); break;case 2:delet(head); break;case 3: modify(head); break;case 4: clean(head); break;case 5: show(head); break;case 0: exit(-1);default: break;}}
free(<span style="font-family: Arial, Helvetica, sans-serif;">head->user</span><span style="font-family: Arial, Helvetica, sans-serif;">);</span>
<span style="font-family:Arial, Helvetica, sans-serif;"> free(head);</span>}
0 0
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- Android Fragment 你应该知道的一切
- SQL Server读写分离研究
- 对象初始化的过程是什么?
- C#读取程序集中嵌入的文件资源
- Odoo 9.0特性
- 通讯录
- 手摇算法
- CFLAGS、CXXFLAGS、LDFLAGS与LIBS
- Linux下使用Squid搭建代理服务器
- 几种CAN应用层协议介绍
- IO流<字符流>FileWriter、FileReader
- What will I do in next 100 days for programming?
- Mac升级到Yosemite之后找不到/usr/include文件夹的解决方法
- c++中的模版和多态之间的关系