c语言,功能简单的电话簿,实现输入,显示,查找的功能
来源:互联网 发布:java post上传文件 编辑:程序博客网 时间:2024/04/30 02:17
感谢论坛里给我提供建议和意见的人,是你们的陪伴让我在风雨中前行,谢谢你们
特别感谢@NeilHappy ,@codesnail ,@xiakan008 ,你们对程序的完善提供的建设性的指导意见
c代码如下:
#include<stdio.h>#include<stdlib.h>#include<string.h>#define LEN sizeof(struct mystr)void main(){ struct mystr { char name[40]; char add[100]; char code[20]; char tel[20]; struct mystr *next; }; FILE *fp; struct mystr *head,*p1,*p2; char select,useless,search_name[40]; int out_err_flag=0,search_flag=0; if((fp=fopen("phonebook.txt","ab+"))==NULL) {printf("File open error!\n");exit(0);} /*SELECT MENU*/ printf("1.Insert a new record\n2.Display existed records\n"); printf("3.Search a record\nELSE Quit\nPlease give your choice:"); scanf("%c%c",&select,&useless); /*select is 1, insert a new record*/ if(select=='1') { printf("NOTE: Use # to finish input\n"); p1=p2=(struct mystr *)malloc(LEN); head=p1; head->next=NULL; do { printf("Input the name:"); gets(p1->name); if(strcmp(p1->name,"#")==0) break; printf("Input the address:"); gets(p1->add); if(strcmp(p1->add,"#")==0) break; printf("Input the post code:"); gets(p1->code); if(strcmp(p1->code,"#")==0) break; printf("Input the telphone number:"); gets(p1->tel); if(strcmp(p1->tel,"#")==0) break; /*write to phonebook.txt*/ if(fwrite(p1,LEN,1,fp)==0) out_err_flag=1; p1=(struct mystr *)malloc(LEN); p2->next=p1; p2=p1; }while(1); printf("With a '#', you have ended the input\n"); if(out_err_flag==1) printf("Errors ocure when writing to file!\n"); } /*select is 2, display existed records*/ else if(select=='2') { printf("NAME\tADD\tCODE\tTEL\n"); p1=(struct mystr *)malloc(LEN); while(!feof(fp)) { if(fread(p1,LEN,1,fp)) printf("%s\t%s\t%s\t%s\n",p1->name,p1->add,p1->code,p1->tel); } free(p1); } /*select is 3, do research*/ else if(select=='3') { printf("Support search by name, please give a name:"); gets(search_name); p1=(struct mystr *)malloc(LEN); while(!feof(fp)) { if(fread(p1,LEN,1,fp)) if(strcmp(p1->name,search_name)==0) { printf("NAME\tADD\tCODE\tTEL\n"); printf("%s\t%s\t%s\t%s\n",p1->name,p1->add,p1->code,p1->tel); search_flag=1; } } if(search_flag!=1) printf("Nothing matched!\n"); free(p1); } /*if select is anything else, quit*/ else exit(0); fclose(fp); getch();}
- c语言,功能简单的电话簿,实现输入,显示,查找的功能
- Python实现简单的电话簿功能
- 编写一个电话簿,可以实现增删查找的功能
- C语言实现的密码输入功能
- C语言实现的密码输入功能
- C语言简单实现日志功能的的题目
- TreeCtrl 查找功能的最简单实现
- C语言简单小功能的实现(不断更新ing)
- Linux下简单的日志功能实现(C语言)
- C语言实现简单的ATM机功能
- 用C语言实现TFTP的简单功能(基于TCP)
- 一个集成输入查找功能的的java简单程序
- C语言实现密码输入功能
- 简单的C语言链表(含输入、输出功能)
- C语言:动态链表的建立,查找,删除,插入功能的实现
- iPhone推送功能的C语言实现
- WinPhone推送功能的C语言实现
- C语言 用链表实现电话本的功能
- Java正则表达式入门(1)
- 标准分
- Java正则表达式入门(2)
- Linux驱动编程 step-by-step (六)
- Java正则表达式入门(3)
- c语言,功能简单的电话簿,实现输入,显示,查找的功能
- VS2005中的条件断点和内存监测
- C++ win32工程如何封装成DLL。
- 深入浅出之正则表达式(一)
- 深入浅出之正则表达式(二)
- hdu1907
- 安装完UBUNTU11.10日历乱码或者出现Invalid UTF-8和GRUB乱码问题解决办法
- 纪念千年一遇的神圣时刻
- ddms - Failed to initialize Monitor Thread: Unable to establish loopback connection