毕业论文论文范文课程设计实践报告法律论文英语论文教学论文医学论文农学论文艺术论文行政论文管理论文计算机安全
您现在的位置: 毕业论文 >> 课程设计 >> 正文

C语言课程设计报告_简单通讯录系统 第2页

更新时间:2007-10-22:  来源:毕业论文

 

delete()
{
struct address *info;
char s[80];
printf("enter name:");
gets(s);
info=find(s);
if (info) {
  if (start==info){
    start=info->next;
    if (start)
      start->prior=NULL;
    else
      last=NULL;
    }
  else{
    info->prior->next=info->next;
    if(info!=last)
      info->prior->next=info->prior;
    else
      last=info->prior;
    }
  free(info);
  }
}

struct address *find(char *name)
{
struct address *info;
info=start;
while(info){
  if(!strcmp(name,info->name)) return info;
  info=info->next;
  }
printf("name not found\n");
return NULL;
}

void list()
{
struct address *info;
info=start;
printf("\n%-20s%-20s%-10s%-10s%-6s\n",
  "姓名","街道","城市","省","邮编");
while(info){
  display(info);
  info=info->next;
  }
printf("\n\n");
}

void display(struct address *info)
{
printf("%-20s%-20s%-10s%-10s%-6s\n",
  info->name,info->street,info->city,info->state,info->zip);
}

void search()
{
char name[40];
struct address *info,*find();
printf("enter name to find:");
gets(name);
info=find(name);
if(!info)
  printf("not found\n");
else
  display(info);
}

void save()
{
struct address *info;
FILE *fp;
if((fp=fopen("mlist","wb"))==NULL){
  printf("can not open file\n");
  exit(1);
  }
printf("\nSaving file\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("mlist","rb"))==NULL){
  printf("can not open file\n");
  return;
  }
while(start){
  info=start->next;
  free(info);
  start=info;
  }
printf("\nLoading file\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] 

C语言课程设计报告_简单通讯录系统 第2页下载如图片无法显示或论文不完整,请联系qq752018766
设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©751com.cn 辣文论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。