| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 517 人关注过本帖
标题:哪位高手给注释一下程序
只看楼主 加入收藏
zyz314154882
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-3-1
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
哪位高手给注释一下程序
  这是我从网上找了代码后修改的 有的地方看不懂 麻烦各位高手注释一下  谢谢



#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct
     {
        
     char name[10];
     char adds[30];
     char mbphnum[15];
     char offphnum[15];
     char hmphnum[15];
     char email[30];
     char qqnum[15];
     }Person;

Person pe[80];                        
int menu_select()
     {
         char c;
         do{
         system("color 07");
         system("cls");
         printf("\t\t *****通讯录***** \n");                              
         printf("\t\t******************\n");                  
         printf("\t\t  1. 添加记录     \n");
         printf("\t\t  2. 显示记录     \n");
         printf("\t\t  3. 删除记录     \n");
         printf("\t\t  4. 查询记录     \n");
         printf("\t\t  5. 修改记录     \n");
         printf("\t\t  6. 保存记录     \n");
         printf("\t\t  0. 退出程序     \n");
         printf("\t\t******************\n");
         printf("\t\t请您选择(0-6):");
         c=getchar();  
         }while(c<'0'||c>'6');
         return(c-'0');
     }
     int Input(Person per[],int n)
{
     int i=0;
     char sign,x[10];                     
     while(sign!='n'&&sign!='N')
     {
      
             printf("姓名:");
             scanf("%s\n",per[n+i].name);
             printf("地址:");
             scanf("%s\n",per[n+i].adds);
             printf("手机号:");
             scanf("%s\n",per[n+i].mbphnum);
             printf("办公电话:");
             scanf("%s\n",per[n+i].offphnum);
             printf("家庭电话:");
             scanf("%s\n",per[n+i].hmphnum);
             printf("电子邮箱:");
             scanf("%s\n",per[n+i].email);
             printf("QQ号:");
             scanf("%s\n",per[n+i].qqnum);
             gets(x);
             printf("是否继续添加?(Y/N)");
             scanf("%c",&sign);
             i++;
         }
         return(n+i);
     }
   

 void Display(Person per[],int n)
     {
         int i;
         
         for(i=1;i<n+1;i++)
         {  printf("*****显示记录*****\n");
            printf("姓名:%s\n",per[i-1].name);
            printf("地址:%s\n",per[i-1].adds);
            printf("手机号:%s\n",per[i-1].mbphnum);
            printf("办公电话:%s\n",per[i-1].offphnum);
            printf("家庭电话:%s\n",per[i-1].hmphnum);
            printf("电子邮箱:%s\n",per[i-1].email);
            printf("QQ号:%s\n",per[i-1].qqnum);
             //printf("%s%s%s%s%s%s%s\n",per[i-1].name,per[i-1].adds,per[i-1].mbphnum,per[i-1].offphnum,per[i-1].hmphnum,per[i-1].email,per[i-1].qqnum);
             if(i>1&&i%10==0)
             {
             printf("***********************************\n");
             printf("\n");
             system("pause");
             printf("***********************************\n");

             }
         }
         printf("**************************************\n");
         system("pause");
     }



 
     int Delete_a_record(Person per[],int n)
     {
         char s[20];
         int i=0,j;
         printf("请输入想删除记录中的名字:");
         scanf("%s",s);
         while(strcmp(per[i].name,s)!=0&&i<n) i++;
         if(i==n)
         {
             printf("通讯录中没有此人!\n");
             return(n);
         }
         for(j=i;j<n-1;j++)
         {
             strcpy(per[j].name,per[j+1].name);
             strcpy(per[j].adds,per[j+1].adds);
             strcpy(per[j].mbphnum,per[j+1].mbphnum);
             strcpy(per[j].offphnum,per[j+1].offphnum);
             strcpy(per[j].hmphnum,per[j+1].hmphnum);
             strcpy(per[j].email,per[j+1].email);
             strcpy(per[j].qqnum,per[j+1].qqnum);
            
         }
         printf("已经成功删除\n");
         return(n-1);

     }



      void Query_a_record(Person per[],int n)
     {
          char s[20];
         int i=0;
         printf("\t请输入想查询的姓名:");
         scanf("\t%s",s);
         while(strcmp(per[i].name,s)!=0&&i<n) i++;
         if(i==n)
         {
             printf("\t通讯录中没有此人!\n");
             return;
         }
         printf("姓名:%s\n",per[i].name);
         printf("地址:%s\n",per[i].adds);
         printf("手机号:%s\n",per[i].mbphnum);
         printf("办公电话:%s\n",per[i].offphnum);
         printf("家庭电话:%s\n",per[i].hmphnum);
         printf("电子邮箱:%s\n",per[i].email);
         printf("QQ号:%s\n",per[i].qqnum);


     }


     void Change(Person per[],int n)
     {
          char s[20];
          int i=0;
          printf("\t请输入想修改的记录中的名字:");
          scanf("%s",s);
          while(strcmp(per[i].name,s)!=0&&i<n) i++;
          if(i==n)
     {
         printf("\t通讯录中没有此人!\n");
         return;
     }
             printf("姓名:");
             scanf("%s\n",per[i].name);
             printf("地址:");
             scanf("%s\n",per[i].adds);
             printf("手机号:");
             scanf("%s\n",per[i].mbphnum);
             printf("办公电话:");
             scanf("%s\n",per[i].offphnum);
             printf("家庭电话:");
             scanf("%s\n",per[i].hmphnum);
             printf("电子邮箱:");
             scanf("%s\n",per[i].email);
             printf("QQ号:");
             scanf("%s\n",per[i].qqnum);
             printf("修改成功!\n");

     }


 void WritetoText(Person per[],int n)
     {
        int i=0;
        FILE *fp;                                            /*定义文件指针*/
        char filename[20];                                   /*定义文件名*/
        printf("\t保存到文件\n");                           /*输入文件名*/
        printf("\t请输入所保存的文件名:");
        scanf("\t%s",filename);
        if((fp=fopen(filename,"w"))==NULL)                  
     {
         printf("\t无法打开文件\n");
         system("pause");
         return;
     }
          fprintf(fp,"******************************************通讯录******************************************\n");
          fprintf(fp,"姓名\n");
          fprintf(fp,"地址\n");
          fprintf(fp,"手机号\n");
          fprintf(fp,"办公电话\n");
          fprintf(fp,"家庭电话\n");
          fprintf(fp,"电子邮箱\n");
          fprintf(fp,"QQ号\n");
          fprintf(fp,"*******************************************************************************************\n");
          while(i<n)
          {
              fprintf(fp,"%s%s%s%s%s%s%s\n",per[i-1].name,per[i-1].adds,per[i-1].mbphnum,per[i-1].offphnum,per[i-1].hmphnum,per[i-1].email,per[i-1].qqnum);
              i++;
          }
          fprintf(fp,"*********************************************************************************************\n");
          fprintf(fp,"***************************************共有%d条记录****************************************\n",n);
          fclose(fp);                                          /*关闭文件*/
          printf("保存成功!\n");


     }


   void main()                                          /*主函数*/
{
     int n=0;
     for(;;)
     {
         switch(menu_select())
         {
         case 1:
         printf("\n\t添加记录到通讯录\n");                          /*添加记录*/
         n=Input(pe,n);
         break;

         case 2:
         printf("\n\t\t\t     通讯录记录表\n");                       /*显示记录*/
         Display(pe,n);
         break;
        
         case 3:
         printf("\n\t从通讯录中删除记录\n");
         n=Delete_a_record(pe,n);                                   /*删除记录*/
         printf("\t");
         system("pause");
         break;

         case 4:
         printf("\n\t在通讯录中查找记录\n");
         Query_a_record(pe,n);                                       /*查找记录*/
         printf("\t");
         system("pause");
         break;
        
         case 5:
         printf("\n\t修改通讯录中的记录\n");
         Change(pe,n);                                              /*修改数据*/
         printf("\t");
         system("pause");
         break;

         case 6:
         printf("\n\t保存功能\n");
         WritetoText(pe,n);                                          /*保存数据*/
         printf("\t");
         system("pause");
         break;

         case 0:
         printf("\n\t\t谢谢使用,再见!\n");                          /*结束程序*/
         printf("\n\t\t");
         system("pause");
         exit(0);
         }
     }
}
搜索更多相关主题的帖子: cls include system email 
2012-03-03 08:53
zyz314154882
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-3-1
收藏
得分:0 
像 ("%s\n",per[n+i].name   这样的给代码我不懂麻烦大家给给注释一下啦   谢谢
2012-03-03 10:53
zhengyuhong
Rank: 2
等 级:论坛游民
帖 子:10
专家分:20
注 册:2012-2-28
收藏
得分:10 
回复 2楼 zyz314154882
这个就是格式输出那些啊
2012-03-03 13:07
榴紫丫
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:33
专家分:135
注 册:2011-11-3
收藏
得分:10 
那个你看不懂的地方在哪
2012-03-04 12:49
快速回复:哪位高手给注释一下程序
数据加载中...
 
   



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

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