通讯录程序(链表版)
来源:互联网 发布:网络医院预约挂号系统 编辑:程序博客网 时间:2024/05/29 18:20
#include <stdio.h>#include <stdlib.h>#include <string.h>#define N 1024struct node{int num ;char name[N];char telephone[N];char address[N];struct node * next;};typedef struct node Node;typedef struct node * Link;void creat_empty_link(Link *head){*head = (Link)malloc(sizeof(Node));(*head)->next = NULL;}void insert_node(Link *head,Link new_node){Link temp = *head;new_node = (Link)malloc(sizeof(Node));if(new_node == NULL){printf("malloc error!\n");exit(-1);}printf("请输入联系人姓名:");scanf("%s",new_node->name);printf("请输入联系人号码:");scanf("%s",new_node->telephone);printf("请输入联系人住址:");scanf("%s",new_node->address);if((*head)->next == NULL){(*head)->next = new_node;new_node->next = NULL;return;}while(temp->next != NULL){temp = temp->next;(new_node->num)++;}temp->next = new_node;new_node->next = NULL;}void del_node(Link *head){char name[N];Link temp;Link p;temp = *head;p = temp;temp = temp->next;scanf("%s",name);while(temp != NULL){if((strcmp((temp->name),name)) == 0){p->next = temp->next;free(temp);printf("删除成功!\n");break;}else{p = temp;temp = temp->next;}}if(temp == NULL){printf("无该联系人!\n");return;}}void display_node(Link * head){Link temp;temp = (*head)->next;if((*head)->next == NULL){printf("还未添加联系人!\n");return ;}printf("序号 姓名 联系方式 家庭住址\n");while(temp != NULL){printf("%4d %5s %15s %15s\n",temp->num,temp->name,temp->telephone,temp->address);temp = temp->next;}printf("\n");}void search(Link *head,char name[]){Link temp;temp = *head;while(temp != NULL){if((strcmp((temp->name),name)) == 0){printf("序号 姓名 联系方式 家庭住址\n");printf("%4d %5s %15s %15s\n",temp->num,temp->name,temp->telephone,temp->address);break;}else{temp = temp->next;}}if(temp == NULL){printf("查无此人!\n");return;}}void menu(){printf("*******欢迎使用通讯录*******\n");printf("* *\n");printf("*1. 添加联系人信息 *\n");printf("*2. 显示联系人信息 *\n");printf("*3. 删除联系人信息 *\n");printf("*4. 修改联系人信息 *\n");printf("*5. 查找联系人信息 *\n");printf("*6. 退出通讯录 *\n");printf("*********************\n");printf("请选择您需要的操作(1~6):");}void change(Link *head,Link new_node){Link temp;temp = *head;int i;char name[N];char telephone[N];char address[N];printf("请输入您需要修改的联系人姓名:");scanf("%s",name);while(temp != NULL){if((strcmp((temp->name),name)) == 0){printf("请选择要修改的选项:\n");printf("1.姓名\n");printf("2.联系方式\n");printf("3.家庭住址\n");scanf("%d",&i);switch(i){case 1:{printf("请输入新的姓名:");scanf("%s",name);strcpy((temp->name),name);}break;case 2:{printf("请输入新的联系方式:");scanf("%s",telephone); strcpy((temp->telephone),telephone);} break;case 3:{ printf("请输入新的家庭住址:");scanf("%s",address);strcpy((temp->address),address);}printf("修改成功!\n");break;default:printf("输入有误!\n");}break;}elsetemp = temp->next;}if(temp == NULL){printf("无该联系人!\n");}}int choose(Link *head,Link new_node){Link temp;int n;int data;int choice;char name[N];temp = *head;scanf("%d",&n);switch(n){case 1: { insert_node(head,new_node);printf("添加成功!\n");for(data = 0;;data++){printf("是否继续添加?(1/0):");scanf("%d",&choice);if(choice == 1){insert_node(head ,new_node);printf("添加成功!\n");}else {system("clear");menu();choose(head,new_node);break;}}} break;case 2: {display_node(head);printf("\n");printf("请选择您接下来的操作:");choose(head,new_node); } break;case 3: { if((*head)->next == NULL) {printf("无联系人可删除,请先添加!\n");system("clear");menu(); choose(head,new_node); } else { printf("请输入需要删除的联系人姓名:");del_node(head);printf("\n");printf("请选择您接下来的操作:");choose(head,new_node); } } break;case 4: {if((*head)->next == NULL){printf("无联系人可修改,请先添加!\n");system("clear");menu();}else{change(head,new_node);printf("\n");printf("请选择接下来的操作:");choose(head,new_node);} } break;case 5: {if((*head)->next == NULL) {printf("无联系人可查找,请先添加!\n");printf("\n"); printf("请选择您接下来的操作:");choose(head,new_node);return;}printf("请输入要查找的联系人姓名:");scanf("%s",name);search(head,name);printf("\n");printf("请选择接下来的操作:");choose(head,new_node); }case 6: { system("clear"); printf("*********************\n"); printf("* *\n"); printf("* 谢谢使用通讯录 *\n"); printf("* *\n"); printf("*********************\n"); } break;default: {printf("输入有误,请重新输入!\n");choose(head,new_node); } break;}}int main(){Link head = NULL;Link new_node = NULL;system("clear");menu();creat_empty_link(&head);choose(&head,new_node);return 0;}
0 0
- 通讯录程序(链表版)
- 通讯录程序
- 通讯录系统(VS2010控制台程序)
- 建立通讯录的程序(用字典)
- C语言(window)通讯录程序
- MFC 通讯录程序思路整理(完成)
- 简单的通讯录程序
- 手机通讯录模拟程序
- C++通讯录程序
- Python通讯录小程序
- 通讯录程序优化
- 小程序-通讯录
- 基于sqlite3实现的简单通讯录程序(控制台)
- 基于sqlite3实现的简单通讯录程序(控制台)
- 一个简单的通讯录程序
- 通讯录管理 程序 VC源代码
- python程序通讯录V1.0
- python程序通讯录V1.1
- LeetCode 282. Expression Add Operators
- java计算文件大小三种方法以及优缺点比较
- Java学习之二-Java反射机制
- IntelliJ IDEA中怎么查看文件中所有方法(类似eclipse里面的outline)
- MySql中时间类型无法设置默认0000-00-00的解决方法
- 通讯录程序(链表版)
- Python高效开发实战(web)——Django、Tornado、Flask、Twisted
- 数据挖掘R语言链接数据库MYSQL
- 【codevs 1085】数字游戏
- Chapter.14 Overloaded Operations and Conversions
- 3DsMax学生版下载问题
- 对指针的使用
- codeforces - 508C - Anya and Ghosts(贪心)
- halcon图像二值化