用c语言写通讯录信息管理系统 要求: (1)数据结构:通讯人员信息结点类型以及相应的结构体; (2)存储结构:选择单链表存储通讯人员信息。 (3)实现功能(以函数方式实现):通讯信息链表创建、通讯信息输入、通讯信息查询、通讯信息修改、通讯信息删除、通讯信息排序、输出或保存到文件。 附:通讯录信息包括:编号、姓名、电话、通信地址、EMAIL等。

时间: 2023-08-02 19:07:21 浏览: 38
好的,这是一个很常见的 C 语言编程实践。我可以给你提供一个大致的思路: 1. 定义通讯人员信息结构体,包括编号、姓名、电话、通信地址、EMAIL等字段。 ``` typedef struct ContactInfo { int id; char name[20]; char phone[20]; char address[50]; char email[50]; struct ContactInfo* next; } ContactInfo; ``` 2. 定义通讯信息链表的数据结构,即链表头结点。 ``` typedef struct ContactList { ContactInfo* head; } ContactList; ``` 3. 实现通讯信息链表创建函数,即初始化链表头结点。 ``` void createContactList(ContactList* list) { list->head = NULL; } ``` 4. 实现通讯信息输入函数,即在链表末尾添加一个通讯人员信息结点。 ``` void addContact(ContactList* list, int id, char* name, char* phone, char* address, char* email) { ContactInfo* newContact = (ContactInfo*)malloc(sizeof(ContactInfo)); newContact->id = id; strcpy(newContact->name, name); strcpy(newContact->phone, phone); strcpy(newContact->address, address); strcpy(newContact->email, email); newContact->next = NULL; if (list->head == NULL) { list->head = newContact; } else { ContactInfo* p = list->head; while (p->next != NULL) { p = p->next; } p->next = newContact; } } ``` 5. 实现通讯信息查询函数,即根据姓名或电话查询通讯人员信息。 ``` void searchContact(ContactList* list, char* keyword) { ContactInfo* p = list->head; while (p != NULL) { if (strstr(p->name, keyword) || strstr(p->phone, keyword)) { printf("%d\t%s\t%s\t%s\t%s\n", p->id, p->name, p->phone, p->address, p->email); } p = p->next; } } ``` 6. 实现通讯信息修改函数,即根据编号修改通讯人员信息。 ``` void updateContact(ContactList* list, int id, char* name, char* phone, char* address, char* email) { ContactInfo* p = list->head; while (p != NULL) { if (p->id == id) { strcpy(p->name, name); strcpy(p->phone, phone); strcpy(p->address, address); strcpy(p->email, email); break; } p = p->next; } } ``` 7. 实现通讯信息删除函数,即根据编号删除通讯人员信息。 ``` void deleteContact(ContactList* list, int id) { ContactInfo* p = list->head; if (p->id == id) { list->head = p->next; free(p); return; } while (p->next != NULL) { if (p->next->id == id) { ContactInfo* tmp = p->next; p->next = tmp->next; free(tmp); return; } p = p->next; } } ``` 8. 实现通讯信息排序函数,即根据姓名或电话排序通讯人员信息。 ``` void sortContact(ContactList* list, char* keyword) { ContactInfo* p = list->head; int count = 0; while (p != NULL) { count++; p = p->next; } ContactInfo** arr = (ContactInfo**)malloc(count * sizeof(ContactInfo*)); p = list->head; for (int i = 0; i < count; i++) { arr[i] = p; p = p->next; } for (int i = 0; i < count - 1; i++) { for (int j = i + 1; j < count; j++) { if (strcmp(keyword == "name" ? arr[i]->name : arr[i]->phone, keyword == "name" ? arr[j]->name : arr[j]->phone) > 0) { ContactInfo* tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; } } } list->head = arr[0]; for (int i = 0; i < count - 1; i++) { arr[i]->next = arr[i + 1]; } arr[count - 1]->next = NULL; free(arr); } ``` 9. 实现输出或保存到文件函数,即将通讯人员信息输出到屏幕或保存到文件中。 ``` void printContactList(ContactList* list) { ContactInfo* p = list->head; while (p != NULL) { printf("%d\t%s\t%s\t%s\t%s\n", p->id, p->name, p->phone, p->address, p->email); p = p->next; } } void saveContactList(ContactList* list, char* filename) { FILE* fp = fopen(filename, "w"); ContactInfo* p = list->head; while (p != NULL) { fprintf(fp, "%d\t%s\t%s\t%s\t%s\n", p->id, p->name, p->phone, p->address, p->email); p = p->next; } fclose(fp); } ``` 这就是一个简单的通讯录信息管理系统的实现。你可以根据实际需求进行修改和优化。

相关推荐

最新推荐

recommend-type

C语言数组实现学生信息管理系统设计

主要为大家详细介绍了C语言数组实现学生信息管理系统设计,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

《图书管理系统》数据结构课设报告(1).doc

数据结构期末大作业,题目是图书管理系统,只完成了图书管理系统的基本功能,使用C语言结构体链表等知识。
recommend-type

基于C语言实现个人通讯录管理系统

之前利用C语言完成了一个关于个人通讯录管理系统的课题,主要是关于联系人的添加、查找、删除、修改、输出以及文件的写入与读出,还有一个甜点功能—模拟通话,它的实现原理也很容易理解,文章末尾会介绍到。...
recommend-type

c语言编写的通讯录管理系统软件课程设计报告

利用 “结构体”、“数组”、“链表” 或“类”、实现通讯录管理系统的数据结构,实现通讯录的按不同“关键字”的排序、查找、加入、删除以及文件加密及存储算法编程。
recommend-type

华为OD机试D卷 - 用连续自然数之和来表达整数 - 免费看解析和代码.html

私信博主免费获取真题解析以及代码
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

list根据id查询pid 然后依次获取到所有的子节点数据

可以使用递归的方式来实现根据id查询pid并获取所有子节点数据。具体实现可以参考以下代码: ``` def get_children_nodes(nodes, parent_id): children = [] for node in nodes: if node['pid'] == parent_id: node['children'] = get_children_nodes(nodes, node['id']) children.append(node) return children # 测试数
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。