利用C语言编写一个通讯录,包括用户界面
来源:互联网 发布:汉奇中走丝编程视频 编辑:程序博客网 时间:2024/06/08 11:57
记得好久之前写的,今天一个学弟问我,我才想起来,主要是依靠链表完成的,细节方面做的还需要改进,
主题架构就是这样了
#include <stdio.h>#include <stdlib.h> #include <string.h>#define TRUE 1#define FALSE 0typedef struct _add{int ID;char Name[20];char Address[30];char Company_Phone[30];char Mobile_Phone[30];}ADD;typedef ADD LinkData;typedef struct _stu{LinkData data;struct _stu *next; }Node;Node * Create_List(){Node *list = (Node*)malloc(sizeof(Node)/sizeof(char));if (list == NULL)return NULL;list->next = NULL; // 空表return list;}int Add_Friend(Node* h){Node* head = Create_List();printf ("\t请输入好友的ID:"); scanf ("%d", &head->data.ID); printf ("\n"); printf ("\t请输入好友的名字:"); scanf ("%s", head->data.Name); printf ("\n"); printf ("\t请输入好友的手机号:"); scanf ("%s", head->data.Mobile_Phone); printf ("\n"); printf ("\t请输入好友的家庭住址:"); scanf ("%s", head->data.Address); printf ("\n"); printf ("\t请输入好友的公司电话:"); scanf ("%s", head->data.Company_Phone); printf ("\n"); Insert_Last(h, head->data);free(head);}int Display(){ printf ("\t*****************************************\n"); printf ("\t~ 欢迎使用通讯录 ~\n"); printf ("\t~ ~\n"); printf ("\t~ 1 >>>>>>>>> 添加好友信息 ~\n"); printf ("\t~ 2 >>>>>>>>> 列表好友信息 ~\n"); printf ("\t~ 3 >>>>>>>>> 搜索好友 ~\n"); printf ("\t~ 4 >>>>>>>>> 删除好友 ~\n"); printf ("\t~ 5 >>>>>>>>> 退出 ~\n"); printf ("\t~ ~\n"); printf ("\t~ ~\n"); printf ("\t~ 作者:李孟龙 ~\n"); printf ("\t*****************************************\n"); printf (" \n"); printf (" \n"); printf ("\t请输入对应数字选择相应功能:"); } int Insert_Last(Node* h,LinkData data)//尾插{if (h == NULL)return FALSE;Node *node = (Node*)malloc(sizeof(Node)/sizeof(char));if (node == NULL){return FALSE;}node->data = data;node->next = NULL;Node* tmp = h;while (tmp->next){tmp = tmp->next;}tmp->next = node;return TRUE;}int Friend_ifo(Node* h){if (h == NULL )return FALSE;printf ("\tID\t姓名\t\t手机号\t\t住址\t\t\t公司电话\n"); Node *tmp = h -> next; while(tmp){ printf ("\t%d\t%s\t\t%s\t\t%s\t\t\t%s\n",tmp->data.ID, tmp->data.Name,tmp->data.Mobile_Phone, tmp->data.Address, tmp->data.Company_Phone); printf("\n");tmp = tmp -> next;}return TRUE;}int Search_Friend(Node* h, char Name[]){if (h == NULL)return FALSE;int count = 0;Node *tmp = h->next;printf ("\tID\t姓名\t\t手机号\t\t住址\t\t\t公司电话\n"); while (tmp){if (strcmp(tmp->data.Name ,Name) == 0){printf ("\t%d\t%s\t\t%s\t\t%s\t\t\t%s\n",tmp->data.ID, tmp->data.Name,tmp->data.Mobile_Phone, tmp->data.Address, tmp->data.Company_Phone);count = count++;}tmp = tmp->next;}if(count == 0){printf("查无此人,谢谢使用\n");}return FALSE;}int Delete_Friend(Node* h, char Name[]){if (h == NULL)return FALSE;printf ("\tID\t姓名\t\t手机号\t\t住址\t\t\t公司电话\n");Node * tmp = h;int count = 0;while (tmp->next){if (strcmp(tmp->next->data.Name, Name) == 0){printf ("\t%d\t%s\t\t%s\t\t%s\t\t\t%s\n",tmp->next->data.ID, tmp->next->data.Name,tmp->next->data.Mobile_Phone, tmp->next->data.Address, tmp->next->data.Company_Phone);count++;//break;}tmp = tmp->next;}if(count == 0){printf("查无此人,谢谢使用\n");}//if (tmp->next == NULL)//return FALSE;if(count == 1){Node *p = tmp->next;tmp->next = p->next;free(p);}if(count >1){printf("输入你要删除的ID:");int a;scanf("%d",&a);Delete_Friend2(h,a);}return TRUE;}int Delete_Friend2(Node* h, int ID){if (h == NULL)return FALSE;Node * tmp = h;while (tmp->next){if (tmp->next->data.ID == ID)break;tmp = tmp->next;}if (tmp->next == NULL)return FALSE;Node *p = tmp->next;tmp->next = p->next;free(p);return TRUE;}int main(){system ("clear");int i=0;Node* head = Create_List();if (head == NULL){printf("创建链表失败\n");return -1;}while(1){char Name[20];Display();int j=0;scanf("%d",&j);switch (j){case 1:j = 0; Add_Friend(head);system ("clear");break;case 2:j = 0;system ("clear");Friend_ifo(head);break;case 3: j = 0;system ("clear"); printf ("\t********************查找好友********************\n"); printf ("\t请输入你要查找好友的姓名: "); scanf ("%s", Name); printf ("\n");Search_Friend(head, Name);break;case 4:system ("clear");j = 0;printf ("\t********************删除好友********************\n"); printf ("\t请输入要删除好友的姓名:"); scanf ("%s", Name); printf ("\n"); Delete_Friend(head,Name);break;case 5:j = 0; system ("clear"); exit(0); break;default:system ("clear");printf("输入有误,重新输入");printf ("\n"); break;}}return 0;}
阅读全文
0 0
- 利用C语言编写一个通讯录,包括用户界面
- C语言通讯录编写
- 用C语言编写通讯录
- C语言编写简易通讯录
- C语言利用结构体实现一个通讯录
- 【c语言】实现一个通讯录
- C语言通讯录(利用数组实现)
- 利用c语言结构体实现通讯录
- 一个通讯录的C语言代码
- 【C语言】实现一个简单的通讯录
- 用C语言实现一个通讯录
- C编写的通讯录
- 用c语言多文件编写1000人的通讯录
- C语言编写—通讯录(小项目)
- C语言编写一个电话本
- C语言通讯录(利用链表实现)
- 利用c语言编写cgi实现搜索
- 用c语言实现一个通讯录; 通讯录可以存储1000个人的信息,信息包括姓名、性别、年龄、电话、住址 提供方法: 1.添加联系人信息 2.删除指定联系人信息 3.查找指定联系人信息 4.修改指定联系&
- vue-cli脚手架的.babelrc文件 详解
- OSG 学习第四天:光照
- CSU-ACM2017暑假训练9-区间DP C
- 良好的编程习惯
- NFS的挂载
- 利用C语言编写一个通讯录,包括用户界面
- 2017 Multi-University Training Contest
- Android的日志工具Log
- KMP算法
- 三十天
- 有关散列表
- 多校4 HDU6069
- pat-aChain the Ropes (25)
- 单向链表的一些基础接口的实现