c语言,功能简单的电话簿,实现输入,显示,查找的功能
2011-11-13 00:55
483 查看
感谢论坛里给我提供建议和意见的人,是你们的陪伴让我在风雨中前行,谢谢你们
特别感谢@NeilHappy ,@codesnail ,@xiakan008 ,你们对程序的完善提供的建设性的指导意见
c代码如下:
特别感谢@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语言实现 一个通讯录(实现 增加、删除、查找、修改、显示、清空功能)
- 设计一个学生成绩管理系统,实现对学生成绩的动态管理,实现对学生成绩的输入,显示,删除,查找,插入,最佳,保存,计算,排序等主要功能
- C语言实现密码输入显示星号 VS2010 亲测通过 功能加强版
- <C语言>如何一步一步根据简单的代码联想到更多的功能?(实现输入一个整数,输出比它小包括它本身的所有素数。)
- 创建一个学生系统,实现一下功能; * 1:增加学生 * 2:显示学生 * 3:修改学生 * 4:删除学生 * 5:查找学生 * 6:退出程序 * 请输入选择(
- 用C语言实现输入密码是显示为***
- 平衡二叉树的 插入 删除 查找 等功能c语言实现 数据结构
- java简单的实现搜索框的下拉显示相关搜索功能
- Python实现简单的电话簿功能
- 如何用C#在winform中实现简单的查找功能
- C语言实现的密码输入功能
- TreeCtrl 查找功能的最简单实现
- 字符串处理是许多程序中非常重要的一部分,它们可以用于文本显示,数据表示,查找键和很多目的.在Unix下,用户可以使用正则表达式的强健功能实现这些 目的,从Java1.4起,Java核心API就引入了java.util.regex程序包,它是一种有价值的基础
- JAVA SPRING MVC 实现一个简单的页面显示功能
- C语言写的简单贪吃蛇程序,实现WASD控制蛇运动,输入输出流为C++
- 用C语言实现一个revert函数,它的功能是将输入的字符串在原串上倒序后返回
- 用C语言实现简单密码输入(初稿)
- 很实用的jQuery事件 - toggle() 方法,简单实现显示隐藏的功能
- 用C语言实现TFTP的简单功能(基于TCP)
- c语言winsock 实现简单的域名解析功能(DNS. v 1.0)