| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 451 人关注过本帖
标题:帮吗修改下加下注释 呵呵 谢了
取消只看楼主 加入收藏
新手NO1
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2010-3-28
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:2 
帮吗修改下加下注释 呵呵 谢了
#include<stdio.h>
#include<stdlib.h>
struct address{
char name[20];
char phone[15];
char build[10];
struct address*next;
struct address*prior;
}list_entry;
struct address*start;/*point to first entry in list*/
struct address*last; /*point to last entry*/
void search();
main()
{
 char s[80],choice;
 struct address*info;
 start=0;  /*zero length list*/
 for(;;){
        choice=menu_select();
        switch(choice){
              case 1:enter();break;
              case 2:delete();break;
              case 3:list();break;
              case 4:search();break;
              case 5:save();break;
              case 6:load();break;
              case 7:exit(0);
              }
        }
    }

    menu_select()
    {
     char s[80];
     int c;
     printf("1.Enter a name\n");
     printf("2.Delete a name\n");
     printf("3.List the file\n");
     printf("4.Search\n");
     printf("5.Save the file\n");
     printf("6.Load the file\n");
     printf("7.Quit\n");
     do{
         printf("Enter your choice:");
         gets(s);
         c=atoi(s);
         }while(c<0||c>7);
         return c;
         }
         enter()
         {
          struct address*info,*dls_store();
          for(;;){
                  info=malloc(sizeof(list_entry));
                  if(info==0){
                             printf("\nout of memory");
                             return;
                             }
                   inputs("enter name:",info->name,20);
                   if(!info->name[0])break;
                   inputs("enter phone:",info->phone,15);
                   inputs("enter build:",info->build,10);
                   start=dls_store(info,start);
                   }
                 }
                 inputs(prompt,s,count)
                 char*prompt;
                 char*s;
                 int count;
                 {
                  char p[255];
                  do{
                    printf(prompt);
                    gets(p);
                    if(strlen(p)>count)printf("\ntoo long\n");
                    }while(strlen(p)>count);
                    strcpy(s,p);
                    }

                    struct address*dls_store(i,top);
                    struct address*i;
                    struct address*top;
                    {  static stuct address*last=0;
                       struct address*old,*p;
                       if(last==0){
                            i->next=0;
                            i->prior=0;
                            last=i;
                            return i;
                            }
                      p=top;
                      old=0;
                      while(p){
                               if(strcmp(p->name,i->name)<0){
                                   old=p;
                                   p=p->next;
                                   }
                              else{
                                  if(p->prior){
                                     p->prior->next=i;
                                     i->next=p;
                                     p->prior=i;
                                     return i;
                                     }
                                  }
                       old->next=i;
                       i->next=0;
                       last=i;
                       return start;
                       }


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


                      struct address*find(name)
                      char*name;
                      {
                        struct addrress*info;
                        info=start;
                        while(info){
                               if(!strcmp(name,info->name))return info;
                               info=info->next;
                               }
                             printf("name not found\n");
                             return 0;
                             }
                      list()
                      {
                        register int t;
                        struct address*info;
                        info=start;
                        while(info){
                            display(info);
                            info=info->next;
                            }
                          printf("\n");
                          }


                          display(info)
                          struct address*info;
                          {
                          printf("%s\n",info->name);
                          printf("%s\n",info->phone);
                          printf("%s\n",info->build);
                          printf("\n");
                        }

                        void search()
                        {
                        char name[20];
                        struct address*info,*find();
                        printf("enter name to fing:");
                        gets(name);
                        info=find(name);
                        if(!info)printf("not found\n");
                        else display(info);
                        }
                        save()
                        {
                         register int t,size;
                         struct address*info;
                         char*p;
                         FILE*fp;
                         if((fp=fopen("mlist","wb"))==0){
                           printf("cannot open file\n");
                           exit(0);
                           }
                           printf("\nsaving file\n");
                           size=sizeof(list_entry);
                           info=start;
                           while(info){
                               p=(char*)info;
                               for(t-0;t<size;t++)
                               putc(*p++,fp);
                               info=info->next;
                               }
                               putc(EOF,fp);
                               fclose(fp);
                               }

                               load()
                               {  register int t,size;
                                  struct address*info,*temp=0;
                                  char*p;
                                  FILE*fp;
                                  if(fp=fopen("mlist","r"))==0){
                                     printf("cannot open file\n");
                                     size=sizeof(list_entry);
                                     start=malloc(size);
                                     if(!start){
                                        printf("out of memory\n");
                                        return;
                                        }
                                  info=start;
                                  p=(char*)info;
                                  while((*p++=getc(fp))!=EOF){
                                     for(t=0;t<size-1;++t)
                                       *p++=getc(fp);
                                     info->next=malloc(size);
                                     if(!info->next){
                                       printf("out of memory\n");
                                       return;
                                       }
                                       info->prior=temp;
                                       temp=info;
                                       info=info->next;
                                       p=(char*)info;
                                       }
                                       temp->next=0;
                                       last=temp;
                                       start->prior=0;
                                       fclose(fp);
                                       }


                                       struct address*didelete(i,top)
                                       struct address*i;
                                       struct address*top;
                                       {
                                       if(i->prior)i->prior->next=i->next;
                                       else{
                                             top=i->next;
                                             if(top)top->prior=0;
                                             }
                                           if(i->next) i->next->prior=i->prior;
                                           return(top);
                                           }




搜索更多相关主题的帖子: 注释 
2010-04-06 09:13
新手NO1
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2010-3-28
收藏
得分:0 
有点长 帮忙改下错误啊 检查好久 就一个问题属实看不出来了
2010-04-07 08:12
新手NO1
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2010-3-28
收藏
得分:0 
  谢谢啦  我去改下
2010-04-08 08:45
快速回复:帮吗修改下加下注释 呵呵 谢了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020124 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved