哪位高手给注释一下程序
这是我从网上找了代码后修改的 有的地方看不懂 麻烦各位高手注释一下 谢谢#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);
}
}
}