C语言通讯录管理系统设计 第3页
图3 删除模块流程图
2.3.3Save( )保存模块 图4 保存模块流程图
保存模块:将最终想要保留的数据信息保存于文件中
void save(){
struct address *info;
FILE *fp;
if((fp=fopen("address.txt","wb"))==NULL){
printf("\nCan't open file.\n");
exit(1);
}
printf("\nSave file success.\n");
info=start;
while(info){
fwrite(info,sizeof(struct address),1,fp);
info=info->next;
}
fclose(fp);
}
2.3.4 search( )查找模块
链表的查找操作是指在已知链表中查找值为某指定值的结点。
void search(){
char name[40];
struct address *info,*find();
printf("\nInput a name to search:");
gets(name);
info=find(name);
if(!info)
printf("Not found\n");
else
display(info);
}
2.4 源程序
#include <stdio.h>
#include <stdlib.h>
struct address{
char name[20];
char street[20];
char city[10];
char state[10];
char eip[7];
struct address *next;
struct address *prior;
}list_entry;
struct address *start;
struct address *last;
void add();
void display();
void search();
void save();
void load();
void list();
struct address *find(char *name);
struct address *dls_store(struct address *,struct address *);
main()
{
clrscr();/*清屏*/
start=last=NULL;
load();/*首先加载文件*/
for (;;){
switch(menu_select()){
case 1:add();break;
case 2:delete();break;
case 3:list();break;
case 4:search();break;
case 5:save();break;
case 6:exit(0);
}
}
}menu_select()
{
char c;
printf("1.Add a record.\n");
上一页 [1] [2] [3] [4] [5] [6] 下一页
C语言通讯录管理系统设计 第3页下载如图片无法显示或论文不完整,请联系qq752018766