void display(struct address *info)
{
printf("%-17s%-15s%-14s%-15s%-6s\n",
info->name,info->street,info->city,info->state,info->eip);
}
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);
}
void save()
{
struct address *info;
FILE *fp;
if((fp=fopen("address","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);
}
void load()
{
struct address *info,*temp=NULL;
FILE *fp;
if((fp=fopen("address","rb"))==NULL){
printf("\nCan't open file\n");
return;
}
while(start){
info=start->next;
free(info);
start=info;
}
printf("\nLoading file success.\n");
start=(struct address *)malloc(sizeof(struct address));
if(!start){
printf("Out of memory!\n");
return;
}
info=start;
while(!feof(fp)){
if(1!=fread(info,sizeof(struct address),1,fp)) break;
info->next=(struct address *)malloc(sizeof(struct address));
if (!info->next){
printf("Out of memory\n");
return;
}
info->prior=temp;
temp=info;
info=info->next;
}
temp->next=NULL;
last=temp;
start->prior=NULL;
fclose(fp);}
上一页 [1] [2] [3] [4] [5] [6] 下一页