/*****************************************************************
- Copyright © 2018 SU_QIAN Ltd. All rights reserved.
- 文件名称:contaction.c
- 创 建 者:ls
- 创建日期:2018年11月22日
- 描 述:本通讯录(红帽子vim编辑器可运行,想要在vs中运行需要修改)实现了增加、删除、查找、修改等功能,但仍有一些小问题待完善,容错性还不算完美;程序代码有些长,因为第一次写这么长的程序,结构不严谨,可能用了许多多余的语句,算是充了一些字数。
- 代码直接拷过来时会出现一些格式错误,我也只是改了一些明显的错误,可能一些格式问题引起的代码错误没被发现,若引用请注意一下。不过最好自己写。
- 通讯录内容:
- ID、姓名、性别、年龄、电话、住址
通过这次编写,能改变输出的颜色,倒是很有意思。老师还给我们提供了从文本中读写的功能,在本代码的最后。
*
*****************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define NONE “\033[0m”
#define BLACK “\033[0;30m”
#define DARK_GRAY “\033[1;30m”
#define BLUE “\033[0;34m”
#define LIGHT_BLUE “\033[1;34m”
#define GREEN “\033[0;32m”
#define LIGHT_GREEN “\033[1;32m”
#define CYAN “\033[0;36m”
#define LIGHT_CYAN “\033[1;36m”
#define RED “\033[0;31m”
#define LIGHT_RED “\033[1;31m”
#define PURPLE “\033[0;35m”
#define LIGHT_PURPLE “\033[1;35m”
#define BROWN “\033[0;33m”
#define YELLOW “\033[1;33m”
#define LIGHT_GRAY “\033[0;37m”
#define WHITE “\033[1;37m”
#define fname “users.db”
#define OK 1
#define ERROR 0
void addusers();
void delusers();
void searchusers();
void reviseusers();
void showusers();
void clearusers();
void inwrong();
void finish();
void print_menu();
void print_submenu4();
void print_submenu3();
void print_submenu2(void);
void idfind();
void namefind();
void telefind();
void iddel();
void namedel();
void teledel();
void yixu(int);
void rvID(int);
void rvname(int);
void rvsex(int);
void rvage(int);
void rvtele(int);
void rvaddress(int);
char menu [][60] = {{" **************************************** \n"},
{" ****** 1.添加联系人2.删除联系人 ********** \n"},
{ “****** 3.查找联系人4.修改联系人**********\n”},
{" ****** 5.显示联系人6.清空联系人**********\n"},
{"****** 0.退出程序 ********** \n"},
{" **************************************** \n"}};
char * submenu3[] = {"****************************************\n",
“***** 1.按ID查找 ****** \n”,
" ***** 2.按姓名查找 ****** \n",
" ***** 3.按电话号码查找 ****** \n",
" ***** 0.返回上一级 ****** \n",
" **************************************** \n"};
char * submenu2[] = {" **************************************** \n",
" ***** 1.按ID删除 ****** \n",
" ***** 2.按姓名删除 ****** \n",
" ***** 3.按电话号码删除 ******\n",
" ***** 0.返回上一级 ****** \n",
" **************************************** \n"};
char *submenu4[] = {" **************************************** \n",
" ***** 1.修改ID ****** \n",
" ***** 2.修改姓名 ****** \n",
" ***** 3.修改性别 ****** \n",
" ***** 4.修改年龄 ****** \n",
" ***** 5.修改公司电话 ****** \n",
" ***** 6.修改家庭住址 ****** \n",
" ***** 0.返回上一级 ****** \n",
" *************************************** \n"};
typedef struct
{
int ID;
char name[10];
char sex[5];
int age;
char tele[12];
char address[20];
int flag;
}NODE;
NODE users[1000];
int loc=0,locc=0;
int main(int argc,char *argv[])
{
int choice,rt;
Rfile(users);
print_menu();
while(1)
{
printf(YELLOW"欢迎使用本通讯录,请输入您的选择:\n"NONE);
rt=scanf("%d",&choice);
if(1 != rt)
{
printf(YELLOW"输入错误!\n"NONE);
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if( getchar() = = ’ \n ’ )
break;
}
getchar();
system(“clear”);
print_menu();
}
else
{
switch(choice)
{
case 1:addusers();print_menu();break;
case 2:delusers();print_menu();break;
case 3:searchusers();getchar();break;
case 4:reviseusers();print_menu();break;
case 5:showusers();print_menu();break;
case 6:clearusers();print_menu();break;
case 0:finish(); Wfile(users);exit(0);
default:inwrong();print_menu();break;
}
}
}
return 0;
}
void rvID(int i)
{
int rvid,rt,ze;
system(“clear”);
printf(BLUE"请输入新的ID:\n"NONE);
rt=scanf("%d",&rvid);
if(1 != rt)
{
printf(YELLOW"输入错误!\n"NONE);
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
}
else
{
system(“clear”);
printf(YELLOW"您即将要将此联系人的ID由%d更改为%d(1/0)\n"NONE,users[i].ID,rvid);
scanf("%d",&ze);
{
if(ze)
{
printf(GREEN"修改前:\nID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
printf(LIGHT_GREEN"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[i].ID,users[i].name,users[i].sex,users[i].age,users[i].tele,users[i].address);
users[i].ID=rvid;
printf(RED"修改后:\nID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
printf(LIGHT_RED"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[i].ID,users[i].name,users[i].sex,users[i].age,users[i].tele,users[i].address);
}
}
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
}
}
void rvage(int i)
{
int rvage,rt,ze;
system(“clear”);
printf(BLUE"请输入新的年龄:\n"NONE);
rt=scanf("%d",&rvage);
if(1 != rt)
{
printf(YELLOW"输入错误!\n"NONE);
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
getchar();
}
else
{
system(“clear”);
printf(YELLOW"您是否要将此联系人的年龄由%d更改为%d(1/0)\n"NONE,users[i].age,rvage);
scanf("%d",&ze);
{
if(ze)
{
printf(GREEN"修改前:\nID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
printf(LIGHT_GREEN"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[i].ID,users[i].name,users[i].sex,users[i].age,users[i].tele,users[i].address);
users[i].age=rvage;
printf(RED"修改后:\nID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
printf(LIGHT_RED"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[i].ID,users[i].name,users[i].sex,users[i].age,users[i].tele,users[i].address);
}
}
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
}
}
void rvname(int i)
{
char rvname[10];
int ze;
system(“clear”);
printf(BLUE"请输入新的姓名:\n"NONE);
scanf("%s",rvname);
system(“clear”);
printf(YELLOW"您是否要将此联系人的姓名由%s更改为%s(1/0)\n"NONE,users[i].name,rvname);
scanf("%d",&ze);
{
if(ze)
{
printf(GREEN"修改前:\nID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
printf(LIGHT_GREEN"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[i].ID,users[i].name,users[i].sex,users[i].age,users[i].tele,users[i].address);
strcpy(users[i].name,rvname);
printf(RED"修改后:\nID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
printf(LIGHT_RED"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[i].ID,users[i].name,users[i].sex,users[i].age,users[i].tele,users[i].address);
}
}
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
}
void rvsex(int i)
{
char rvsex[5];
int ze;
system(“clear”);
printf(BLUE"请输入新的性别:\n"NONE);
scanf("%s",rvsex);
system(“clear”);
printf(YELLOW"您是否要将此联系人的姓名由%s更改为%s(1/0)\n"NONE,users[i].sex,rvsex);
scanf("%d",&ze);
{
if(ze)
{
printf(GREEN"修改前:\nID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
printf(LIGHT_GREEN"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[i].ID,users[i].name,users[i].sex,users[i].age,users[i].tele,users[i].address);
strcpy(users[i].sex,rvsex);
printf(RED"修改后:\nID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
printf(LIGHT_RED"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[i].ID,users[i].name,users[i].sex,users[i].age,users[i].tele,users[i].address);
}
}
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
}
void rvtele(int i)
{
char rvtele[12];
int ze;
system(“clear”);
printf(BLUE"请输入新的电话号码:\n"NONE);
scanf("%s",rvtele);
system(“clear”);
printf(YELLOW"您是否要将此联系人的电话号码由%s更改为%s(1/0)\n"NONE,users[i].tele,rvtele);
scanf("%d",&ze);
{
if(ze)
{
printf(GREEN"修改前:\nID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
printf(LIGHT_GREEN"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[i].ID,users[i].name,users[i].sex,users[i].age,users[i].tele,users[i].address);
strcpy(users[i].tele,rvtele);
printf(RED"修改后:\nID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
printf(LIGHT_RED"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[i].ID,users[i].name,users[i].sex,users[i].age,users[i].tele,users[i].address);
}
}
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
}
void rvaddress(int i)
{
char rvaddress[20];
int ze;
system(“clear”);
printf(BLUE"请输入新的家庭住址:\n"NONE);
scanf("%s",rvaddress);
printf(YELLOW"您是否要将此联系人的家庭住址由%s更改为%s(1/0)\n"NONE,users[i].address,rvaddress);
scanf("%d",&ze);
{
if(ze)
{
printf(GREEN"修改前:\nID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
printf(LIGHT_GREEN"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[i].ID,users[i].name,users[i].sex,users[i].age,users[i].tele,users[i].address);
strcpy(users[i].address,rvaddress);
printf(RED"修改后:\nID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
printf(LIGHT_RED"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[i].ID,users[i].name,users[i].sex,users[i].age,users[i].tele,users[i].address);
}
}
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
}
void print_submenu4()
{
int i;
system(“clear”);
for(i=0;i<8;i++)
{
printf(BLUE"%s\n"NONE,submenu4[i]);
}
}
void yixu(int start)
{
for(start;start<=locc;start++)
{
users[start].ID=users[start+1].ID;
strcpy(users[start].name,users[start+1].name);
strcpy(users[start].sex,users[start+1].sex);
users[start].age=users[start+1].age;
strcpy(users[start].tele,users[start+1].tele);
strcpy(users[start].address,users[start+1].address);
users[start].flag=users[start+1].flag;
}
loc–;
}
void teledel()
{
int i,flag=0,flag1=0,rt;
char msure;
char deltele[12];
system(“clear”);
printf(BLUE"请输入你想要删除的联系人的电话号码:\n"NONE);
scanf("%s",deltele);
for(i=0;i<loc;i++)
{
if(!strcmp(deltele,users[i].name))
{
flag=1;
while(1)
{
printf(GREEN"ID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
printf(LIGHT_GREEN"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[i].ID,users[i].name,users[i].sex,users[i].age,users[i].tele,users[i].address);
printf(YELLOW"您是否删除此联系人?(y/n)\n"NONE);
rt=scanf("%s",&msure);
if(1 != rt)
{
printf(YELLOW"输入错误!\n"NONE);
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
getchar();
system(“clear”);
continue;;
}
else
break;
}
if(‘y’ = = msure || ‘Y’ = = msure)
{
yixu(i);
locc=loc;
printf(PURPLE"删除成功!\n"NONE);
flag1=1;
}
}
}
if(!flag)
{
printf(BROWN"未成功找到名字为\t%s\t的联系人!\n"NONE,deltele);
}
if(!flag1)
{
printf(BROWN"已取消删除名字为\t%s\t的联系人!\n"NONE,deltele);
}
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
}
void namedel()
{
int i,flag=0,flag1=0,rt;
char msure;
char delname[10];
system(“clear”);
printf(BLUE"请输入你想要删除的联系人的姓名:\n"NONE);
scanf("%s",delname);
for(i=0;i<loc;i++)
{
if(!strcmp(delname,users[i].name))
{
flag=1;
while(1)
{
printf(GREEN"ID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
printf(LIGHT_GREEN"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[i].ID,users[i].name,users[i].sex,users[i].age,users[i].tele,users[i].address);
printf(YELLOW"您是否删除此联系人?(y/n)\n"NONE);
rt=scanf("%s",&msure);
if(1 != rt)
{
printf(YELLOW"输入错误!\n"NONE);
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
getchar();
system(“clear”);
continue;;
}
else
break;
}
if(‘y’= = msure || ‘Y’= = msure)
{
yixu(i);
locc=loc;
printf(PURPLE"删除成功!\n"NONE);
flag1=1;
}
}
}
if(!flag)
{
printf(BROWN"未找到删除名字为\t%s\t的联系人!\n"NONE,delname);
}
if(!flag1)
{
printf(BROWN"已取消删除名字为\t%s\t的联系人!\n"NONE,delname);
}
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
}
void iddel()
{
int delid,i,flag=0,flag1=0,msure,rt,rt1;
system(“clear”);
printf(BLUE"请输入你想要删除的联系人的ID:\n"NONE);
rt=scanf("%d",&delid);
if(1 != rt)
{
printf(YELLOW"输入错误!\n"NONE);
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
getchar();
}
else
{
for(i=0;i<loc;i++)
{
if(delid= =users[i].ID)
{
flag=1;
while(1)
{
printf(GREEN"ID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
printf(LIGHT_GREEN"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[i].ID,users[i].name,users[i].sex,users[i].age,users[i].tele,users[i].address);
printf(YELLOW"您确定删除此联系人?(1/0)\n"NONE);
rt1=scanf("%d",&msure);
if(1 != rt1)
{
printf(YELLOW"输入错误!\n"NONE);
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
getchar();
system(“clear”);
continue;;
}
else
break;
}
if(msure = = 1)
{
yixu(i);
locc=loc;
printf(PURPLE"删除成功!\n"NONE);
flag1=1;
}
}
}
if(!flag)
{
printf(BROWN"未成功找到ID为\t%d\t的联系人!\n"NONE,delid);
}
if(!flag1)
{
printf(BROWN"已取消删除ID为\t%d\t的联系人!\n"NONE,delid);
}
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
}
}
void idfind()
{
int rt,findid,i,flag=0;
system(“clear”);
printf(BLUE"请输入你想要查找的联系人的ID:\n"NONE);
rt=scanf("%d",&findid);
if(1 != rt)
{
printf(YELLOW"输入错误!\n"NONE);
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
getchar();
}
else
{
for(i=0;i<loc;i++)
{
if(findid= =users[i].ID)
{
printf(GREEN"ID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
printf(LIGHT_GREEN"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[i].ID,users[i].name,users[i].sex,users[i].age,users[i].tele,users[i].address);
flag=1;
}
}
if(!flag)
{
system(“clear”);
printf(BROWN"未查到ID为\t%d\t的联系人!\n"NONE,findid);
}
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
}
}
void namefind()
{
char findname[10];
int i,flag=0;
system(“clear”);
printf(BLUE"请输入你想要查找的联系人的姓名:\n"NONE);
scanf("%s",findname);
for(i=0;i<loc;i++)
{
if(!strcmp(findname,users[i].name))
{
printf(GREEN"ID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
printf(LIGHT_GREEN"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[i].ID,users[i].name,users[i].sex,users[i].age,users[i].tele,users[i].address);
flag=1;
}
}
if(!flag)
{
system(“clear”);
printf(BROWN"未查到姓名为\t%s\t的联系人!\n"NONE,findname);
}
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
}
void telefind()
{
char findtele[12];
int i,flag=0;
system(“clear”);
printf(BLUE"请输入你想要查找的联系人的电话号码:\n"NONE);
scanf("%s",findtele);
for(i=0;i<loc;i++)
{
if(!strcmp(findtele,users[i].tele))
{
printf(GREEN"ID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
printf(LIGHT_GREEN"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[i].ID,users[i].name,users[i].sex,users[i].age,users[i].tele,users[i].address);
flag=1;
}
}
if(!flag)
{
system(“clear”);
printf(BROWN"未查到电话号码为%s的联系人!\n"NONE,findtele);
}
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
}
void print_submenu2(void)
{
int i;
system(“clear”);
for(i=0;i<6;i++)
{
printf(BLUE"%s\n"NONE,submenu2[i]);
}
}
void print_menu(void)
{
int i;
system(“clear”);
for(i=0;i<6;i++)
{
printf(BLUE"%s\n"NONE,menu[i]);
}
}
void print_submenu3(void)
{
int i;
system(“clear”);
for(i=0;i<6;i++)
{
printf(BLUE"%s\n"NONE,submenu3[i]);
}
}
void addusers(void )
{
char add1;
int rt;
system(“clear”);
if(loc>=1000)
{
printf(YELLOW"通讯录已满,无法继续添加!\n"NONE);
}
else
{
while(loc<1000)
{
printf(BLUE"请输入联系人的姓名:\n"NONE);
scanf("%s",users[loc].name);
system(“clear”);
printf(RED"请输入联系人的性别:\n"NONE);
scanf("%s",users[loc].sex);
while(1)
{
system(“clear”);
printf(YELLOW"请输入联系人的年龄:\n"NONE);
rt=scanf("%d",&users[loc].age);
if(1 != rt)
{
printf(YELLOW"输入错误!\n"NONE);
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
getchar();
continue;
}
else break;
}
system(“clear”);
printf(BROWN"请输入联系人的公司电话:\n"NONE);
scanf("%s",users[loc].tele);
system(“clear”);
printf(PURPLE"请输入联系人的家庭住址:\n"NONE);
scanf("%s",users[loc].address);
system(“clear”);
users[loc].ID=loc+1;
users[loc].flag=1;
loc++;
locc++;
system(“clear”);
printf(GREEN"是否继续添加?(y/n)\n"NONE);
scanf("%s",&add1);
if( ‘y’ = = add1 || ‘Y’ = = add1)
{
system(“clear”);
continue;
}
else
{
break;
}
}
}
}
void delusers()
{
int find,end,rt;
while(1)
{
end=0;
print_submenu2();
printf(BLUE"请输入你想用的删除方式:\n"NONE);
rt=scanf("%d",&find);
if(1 != rt)
{
printf(YELLOW"输入错误!\n"NONE);
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
getchar();
}
else
{
switch(find)
{
case(1):iddel();break;
case(2):namedel();break;
case(3):teledel();break;
case(0):end=1;break;
default:inwrong();break;
}
if(end = = 1)
{
break;
}
}
}
}
void searchusers()
{
int rt,find,end;
while(1)
{
end=0;
print_submenu3();
printf(BLUE"请输入你想用的查找方式:\n"NONE);
rt=scanf("%d",&find);
if(1 != rt)
{
printf(YELLOW"输入错误!\n"NONE);
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
getchar();
}
else
{
switch(find)
{
case(1):idfind();break;
case(2):namefind();break;
case(3):telefind();break;
case(0):end=1;break;
default:inwrong();break;
}
if(end = = 1)
{
break;
}
}
}
print_menu();
}
void reviseusers()
{
int rvid,i,rvflag,cho,endflag,rt,rt1;
while(1)
{
rvflag=0;
endflag=0;
system(“clear”);
printf(BLUE"请输入您想要修改的联系人的ID:\n"NONE);
rt=scanf("%d",&rvid);
if(1 != rt)
{
printf(YELLOW"输入错误!\n"NONE);
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
getchar();
}
else
{
for(i=0;i<loc;i++)
{
if(users[i].ID = = rvid)
{
rvflag=1;
break;
}
}
if(rvflag)
{
while(1)
{
system(“clear”);
print_submenu4();
printf(BLUE"ID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
printf(YELLOW"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[i].ID,users[i].name,users[i].sex,users[i].age,users[i].tele,users[i].address);
printf(RED"请输入你想要修改的联系人内容:\n"NONE);
rt1=scanf("%d",&cho);
if(1 != rt1)
{
printf(YELLOW"输入错误!\n"NONE);
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
getchar();
}
else
{
switch(cho)
{
case 1:rvID(i);break;
case 2:rvname(i);break;
case 3:rvsex(i);break;
case 4:rvage(i);break;
case 5:rvtele(i);break;
case 6:rvaddress(i);break;
case 0:endflag=1;break;
}
if(endflag)
{
break;
}
}
}
}
else
{
printf(LIGHT_PURPLE"未搜索到此ID\n按任意键继续。。。\n"NONE);
while(getchar()!=EOF)
{
if(getchar()= =’\n’) break;
}
break;
}
if(endflag)
{
break;
}
}
}
}
void showusers()
{
char ch;
system(“clear”);
while(1)
{
int haoma=0;
printf(BLUE"ID\t姓名\t\t性别\t年龄\t\t公司电话\t家庭住址\n"NONE);
for(haoma;haoma<loc;haoma++)
{
if(users[haoma].flag)
{
printf(YELLOW"%-8d%-16s%-8s%-16d%-16s%s\n"NONE,users[haoma].ID,users[haoma].name,users[haoma].sex,users[haoma].age,users[haoma].tele,users[haoma].address);
}
}
if(haoma>=loc)
{
break;
}
}
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
}
void clearusers()
{
char cho;
int i;
system(“clear”);
printf(YELLOW"是否清空通讯录?(y/n)\n"NONE);
scanf("%s",&cho);
if( ‘y’ = = cho || ‘Y’= = cho )
{
for(i=0;i<=locc;i++)
{
yixu(0);
}
locc=loc;
printf(LIGHT_PURPLE"清空完毕!\n按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
}
}
void inwrong()
{
system(“clear”);
printf(PURPLE"输入错误,请重新输入:\n"NONE);
printf(LIGHT_PURPLE"按任意键继续。。。\n"NONE);
while((getchar())!=EOF)
{
if(getchar()= =’\n’)
break;
}
}
void finish()
{
system(“clear”);
printf(CYAN"感谢您的使用,再见!\n"NONE);
}
int Rfile(NODE txl[])
{
FILE *fp;
int i, size;
NODE e;
if ((fp = fopen(fname, “r”)) = = NULL)
{
perror(“打开文件失败”);
return ERROR;
}
fseek(fp, 0, SEEK_END);
size = ftell(fp) / sizeof(NODE);
rewind(fp);
for (i = 0; i<size; i++) {
fread(&e, sizeof(NODE), 1, fp);
txl[i] = e;
}
loc = i;
fclose(fp);
return OK;
}
int Wfile(NODE txl[])
{
FILE *fp;
NODE e;
int i;
if ((fp = fopen(fname, “w”)) == NULL)
{
perror(“打开文件失败”);
return ERROR;
}
for (i = 0; i<loc; i++)
{
e = txl[i];
fwrite(&e, sizeof(NODE), 1, fp);
}
fclose(fp);
return OK;
}