通讯录的实现
来源:互联网 发布:在淘宝网上开店步骤 编辑:程序博客网 时间:2024/06/07 11:57
#ifndef _CONTACTS_H_#define _CONTACTS_H_#define NAME_LENGTH 20#define SEX_LENGTH 10#define TELE_LENGTH 11#define ADDR_LENGTH 30#define MAX 1000struct PeopleInfo{char name[NAME_LENGTH];int age;char sex[SEX_LENGTH];char tele[TELE_LENGTH];char addr[ADDR_LENGTH];};struct Contacts{struct PeopleInfo person[MAX];int count;}typedef struct Contacts *pcontacts;int add_contacts(pcontacts pcon); int dele_contacts(pcontacts pcon); int clear_contacts(pcontacts pcon); int find_contacts(pcontacts pcon); int modify_contacts(pcontacts pcon); void show_contacts(pcontacts pcon); #endif _CONTACTS_H_
contacts.c
/*实现一个通讯录; 通讯录可以用来存储1000个人的信息,每个人的信息包括: 姓名、性别、年龄、电话、住址 提供方法: 1. 添加联系人信息 2. 删除指定联系人信息 3. 查找指定联系人信息 4. 修改指定联系人信息 5. 显示所有联系人信息 6. 清空所有联系人*/#include"contacts.h"#include<string.h>int find_entry(pcontacts pcon){int i=0;char name[NAME_LENGTH];printf("input name:");scanf("%s",name);for(i=0;i<pcon->count;i++){if(strcmp(person[i].name,name)==0){return i;}}return -1;}int add_contacts(pcontacts pcon){if(pcon->count==max){printf("full!");}printf("input name:"); scanf("%s",pcon->person[pcon->count].name);printf("input age:"); scanf("%d",&pcon->person[pcon->count].age);printf("input sex:"); scanf("%s",pcon->person[pcon->count].sex);printf("input tele:"); scanf("%s",pcon->person[pcon->count].tele); printf("input addr:"); scanf("%s",pcon->person[pcon->count].addr);pcon->count++;return 1;}int dele_contacts(pcontacts pcon){int i=0;int ret=find_entry(pcon);if(ret!=-1){for(i=ret;i<pcon->count;i++){pcon->person[i]=pcon->person[i+1];}pcon->count--;return 1;}else{printf("not exist!\n"); return -1;}}int clear_contacts(pcontacts pcon){pcon->count=0;return 1;}int find_contacts(pcontacts pcon){int ret = find_entry(pcon); if(ret != -1) { printf("name:%s",pcon->person[ret].name); return 1; } else { printf("not exist!\n"); return -1; }}int modify_contacts(pcontacts pcon){int ret = find_entry(pcon); if(ret != -1) { printf("input name:"); scanf("%s",pcon->person[ret].name); printf("input sex:"); scanf("%s",pcon->person[ret].sex); printf("input age:"); scanf("%s",pcon->person[ret].age); printf("input tele:"); scanf("%s",pcon->person[ret].tele); printf("input addr:"); scanf("%s",pcon->person[ret].addr); return 1; } else { printf("not exist!\n"); return -1; } } void show_contacts(pcontacts pcon){int i=0;printf("\tname\tage\tsex\ttele\taddr");for(i=0;i<pcon->count;i++){ printf("%10s\t",pcon->person[i].name); printf("%5s\t",pcon->person[i].sex); printf("%5d\t",pcon->person[i].age); printf("%12s\t",pcon->person[i].tele); printf("%20s\t",pcon->person[i].addr); } printf("\n");}
主函数
#include<stdio.h>#include<string.h>#include"contacts.h"int main() { int n = 1; struct Contacts people; people.count = 0;printf("input number:");scanf("%d",&n);switch(n){case 1:add_contacts(&people);break; case 2:dele_contacts(&people);break; case 3:clear_contacts(&people);break; case 4:find_contacts(&people);break;case 5:modify_contacts(&people);break;case 6:show_contacts(&people);break;default:printf("not exist\n");break;}return 0;}
0 0
- android 通讯录的实现
- 通讯录的实现
- 手机通讯录的实现
- 通讯录的简单实现
- 通讯录的简单实现
- 通讯录的实现
- 通讯录的静态实现
- 通讯录的动态实现
- 通讯录的简单实现
- 通讯录的原型实现(-)
- 通讯录的实现
- 静态通讯录的实现
- 简单通讯录的实现
- 动态通讯录的实现
- 简单通讯录的实现
- 二维码通讯录的实现
- 手机通讯录的简单实现
- 通讯录的C++语言实现
- ie 浏览器无法保存cookie,且与域名包含了下划线(_)有关系的问题
- 异步上传文件插件-ajaxfileupload.js简单例子
- psch和ssch的作用在WCDMA
- 域名解析中A记录、CNAME、MX记录、NS记录的区别和联系
- SubViews中如果根据tag获取到指点的 UIView – viewWithTag
- 通讯录的实现
- 两种方法测试大小端
- Zend Framework2使用Faq随记
- android如何手动生成设备节点
- [protobuf] 开源点评:Protocol Buffers介绍
- Java日期操作常用方法
- yii2ecommerce 手册
- 安卓service需要注意的东西
- ini文件中动态数组的格式和QSetting的读写