C语言通讯录管理系统开发
生活随笔
收集整理的這篇文章主要介紹了
C语言通讯录管理系统开发
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
C語(yǔ)言通訊錄管理系統(tǒng)開發(fā)
- 程序介紹
- 代碼
程序介紹
通訊錄管理系統(tǒng)主要是實(shí)現(xiàn)對(duì)聯(lián)系人的增、刪、查以及顯示的基本操作。用戶可以根據(jù)自己的需要在功能菜單中選擇相應(yīng)的操作,實(shí)現(xiàn)對(duì)聯(lián)系人的快速管理。
操作流程
用戶在編譯完成后會(huì)產(chǎn)生一個(gè)系統(tǒng)的可執(zhí)行文件,用戶只要雙擊可執(zhí)行文件就可以進(jìn)入系統(tǒng),進(jìn)入系統(tǒng)的功能選擇菜單,如圖所示,用戶根據(jù)自己的需要選擇相應(yīng)的操作。
代碼
#include<stdio.h> #include<stdlib.h> #include<dos.h> #include <conio.h> #include<string.h> struct Info {char name[15];/*姓名*/char city[10];/*城市*/char province[10];/*省*/char state[10];/*國(guó)家*/char tel[15];/*電話*/ }; typedef struct node/*定義通訊錄鏈表的結(jié)點(diǎn)結(jié)構(gòu)*/ {struct Info data;struct node *next; }Node,*link;void stringinput(char *t,int lens,char *notice) {char n[50];do{printf("%s",notice); /*顯示提示信息*/scanf("%s",&n); /*輸入字符串*/if(strlen(n)>lens)printf("\n exceed the required length! \n"); /*超過lens值重新輸入*/}while(strlen(n)>lens);strcpy(t,n); /*將輸入的字符串拷貝到字符串t中*/ }void enter(link l)/*輸入記錄*/ {Node *p,*q;q=l;while(1){p=(Node*)malloc(sizeof(Node));/*申請(qǐng)結(jié)點(diǎn)空間*/if(!p)/*未申請(qǐng)成功輸出提示信息*/{printf("memory malloc fail\n");return;}stringinput(p->data.name,15,"enter name:");/*輸入姓名*/if(strcmp(p->data.name,"0")==0)/*檢測(cè)輸入的姓名是否為0*/break;stringinput(p->data.city,10,"enter city:");/*輸入城市*/stringinput(p->data.province,10,"enter province:");/*輸入省*/stringinput(p->data.state,10,"enter status:");/*輸入國(guó)家*/stringinput(p->data.tel,15,"enter telephone:");/*輸入電話號(hào)碼*/p->next=NULL;q->next=p;q=p;} }void del(link l) {Node *p,*q;char s[20];q=l;p=q->next;printf("enter name:");scanf("%s",s);/*輸入要?jiǎng)h除的姓名*/while(p){if(strcmp(s,p->data.name)==0)/*查找記錄中與輸入名字匹配的記錄*/{q->next=p->next;/*刪除p結(jié)點(diǎn)*/free(p);/*將p結(jié)點(diǎn)空間釋放*/printf("delete successfully!");break;}else{q=p;p=q->next;}}getch(); } void display(Node *p) {printf("MESSAGE \n");printf("name:%15s\n",p->data.name);printf("city: %10s\n",p->data.city);printf("province:%10s\n",p->data.province);printf("state: %10s\n",p->data.state);printf("telphone:%15s\n",p->data.tel);} void search(link l) {char name[20];Node *p;p=l->next;printf("enter name to find:");scanf("%s",name);/*輸入要查找的名字*/while(p){if(strcmp(p->data.name,name)==0)/*查找與輸入的名字相匹配的記錄*/{display(p);/*調(diào)用函數(shù)顯示信息*/getch();break;}elsep=p->next;} } void list(link l) {Node *p;p=l->next;while(p!=NULL)/*從首節(jié)點(diǎn)一直遍歷到鏈表最后*/{display(p);p=p->next;}getch(); }void save(link l) {Node *p;FILE *fp;p=l->next;if((fp=fopen("f:\\adresslist","wb"))==NULL){printf("can not open file\n");exit(1);}printf("\nSaving file\n");while(p)/*將節(jié)點(diǎn)內(nèi)容逐個(gè)寫入磁盤文件中*/{fwrite(p,sizeof(Node),1,fp);p=p->next;}fclose(fp);getch(); } void load(link l) {Node *p,*r;FILE *fp;l->next=NULL;r=l;if((fp=fopen("f:\\adresslist","rb"))==NULL){printf("can not open file\n");exit(1);};printf("\nLoading file\n");while(!feof(fp)){p=(Node*)malloc(sizeof(Node));/*申請(qǐng)節(jié)點(diǎn)空間*/if(!p){printf("memory malloc fail!");return;}if(fread(p,sizeof(Node),1,fp)!=1)/*讀記錄到節(jié)點(diǎn)p中*/break;else{p->next=NULL;r->next=p;/*插入鏈表中*/r=p;}}fclose(fp);getch(); }int menu_select() {int i;printf("\n\n\t *************************ADDRESS LIST*************************\n");printf("\t|* 1.input record *|\n");printf("\t|* 2.delete record *|\n");printf("\t|* 3.list record *|\n");printf("\t|* 4.search record *|\n");printf("\t|* 5.save record *|\n");printf("\t|* 6.load record *|\n");printf("\t|* 7.Quit *|\n");printf("\t **************************************************************\n");do{printf("\n\tEnter your choice:");scanf("%d",&i);}while(i<0||i>7);return i; } main() {link l;l=(Node*)malloc(sizeof(Node));if(!l){printf("\n allocate memory failure "); /*如沒有申請(qǐng)到,輸出提示信息*/return 0; /*返回主界面*/}l->next=NULL;system("cls");while(1){system("cls");switch(menu_select()){case 1:enter(l);break;case 2:del(l);break;case 3:list(l);break;case 4:search(l);break;case 5:save(l);break;case 6:load(l);break;case 7:exit(0);}} }總結(jié)
以上是生活随笔為你收集整理的C语言通讯录管理系统开发的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于做ceb转换cebx遇到的问题及解决
- 下一篇: 【Python】9×9数独计算器