|
|
|
@ -1,19 +1,48 @@
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <process.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
//定义函数
|
|
|
|
|
FILE *fp; //文件指针
|
|
|
|
|
void menu();
|
|
|
|
|
void add();
|
|
|
|
|
void search();
|
|
|
|
|
void modify();
|
|
|
|
|
void dele();
|
|
|
|
|
void look();
|
|
|
|
|
void quit();
|
|
|
|
|
void enroll();
|
|
|
|
|
void login();
|
|
|
|
|
void reenroll();
|
|
|
|
|
void jiemian();
|
|
|
|
|
void ycmm();
|
|
|
|
|
void relogin();
|
|
|
|
|
|
|
|
|
|
int n;
|
|
|
|
|
int m;
|
|
|
|
|
int t;
|
|
|
|
|
int offset;
|
|
|
|
|
char mima_[10];
|
|
|
|
|
char MIMA[4]="5555";
|
|
|
|
|
|
|
|
|
|
struct manager
|
|
|
|
|
{
|
|
|
|
|
char name[10];
|
|
|
|
|
char password[10];
|
|
|
|
|
}manage[5];
|
|
|
|
|
|
|
|
|
|
//主函数
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
menu();
|
|
|
|
|
int a=0;
|
|
|
|
|
n=0;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
jiemian();
|
|
|
|
|
getchar();
|
|
|
|
|
printf("\n按1继续回到主界面,其它任意键退出:");
|
|
|
|
|
a=getch();
|
|
|
|
|
}while(a==49);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
//通讯录结构体
|
|
|
|
@ -25,35 +54,192 @@ struct user
|
|
|
|
|
char tel2[15]; //电话2
|
|
|
|
|
char email[20]; //电子邮箱
|
|
|
|
|
}user[50];
|
|
|
|
|
//菜单
|
|
|
|
|
void menu()
|
|
|
|
|
|
|
|
|
|
void jiemian()
|
|
|
|
|
{
|
|
|
|
|
system("cls");
|
|
|
|
|
system("color f3");
|
|
|
|
|
int n;
|
|
|
|
|
printf("\n\n\n\n\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:--输入数 <1-5>选择功能--:\n\n");
|
|
|
|
|
printf("\t\t: 1.注册 :\n");
|
|
|
|
|
printf("\t\t: 2.登录 :\n");
|
|
|
|
|
printf("\t\t:--输入数 <1-2>选择功能--:\n\n");
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
switch(n)
|
|
|
|
|
{
|
|
|
|
|
case 1: add(); break; //添加
|
|
|
|
|
case 2: search(); break; //查询
|
|
|
|
|
case 3: modify(); break; //修改
|
|
|
|
|
case 4: look(); break; //浏览
|
|
|
|
|
case 5: return; break; //退出
|
|
|
|
|
case 1: enroll(); break; //注册
|
|
|
|
|
case 2: login(); break; //登录
|
|
|
|
|
default: return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//添加用户信息
|
|
|
|
|
//注册
|
|
|
|
|
void enroll()
|
|
|
|
|
{
|
|
|
|
|
system("cls");
|
|
|
|
|
int anhao; //管理员密匙
|
|
|
|
|
char zhanghao[10];
|
|
|
|
|
char mima1[10];
|
|
|
|
|
char mima2[10];
|
|
|
|
|
|
|
|
|
|
//管理员注册
|
|
|
|
|
printf("\n请输入暗号:");
|
|
|
|
|
ycmm();
|
|
|
|
|
|
|
|
|
|
//暗号核对正确
|
|
|
|
|
if(!strcmp(mima_,MIMA)){
|
|
|
|
|
fp=fopen("manager.txt","ab");
|
|
|
|
|
struct manager one;
|
|
|
|
|
printf("\n\t\t\t请输入新管理员账号:");
|
|
|
|
|
scanf("%s",zhanghao);
|
|
|
|
|
printf("\n\t\t\t请输入新管理员密码:");
|
|
|
|
|
ycmm();
|
|
|
|
|
strcpy(mima1,mima_);
|
|
|
|
|
printf("\n\t\t\t请再次确认密码:");
|
|
|
|
|
ycmm();
|
|
|
|
|
strcpy(mima2,mima_);
|
|
|
|
|
if(!strcmp(mima1,mima2)){
|
|
|
|
|
strcpy(one.name,zhanghao);
|
|
|
|
|
strcpy(one.password,mima1);
|
|
|
|
|
fprintf(fp,"%-10s%-10s",one.name,one.password);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
fclose(fp);reenroll();return;
|
|
|
|
|
}
|
|
|
|
|
printf("\t\t\t注册成功!\n\n");
|
|
|
|
|
fclose(fp);
|
|
|
|
|
printf("3秒后进入管理员界面");
|
|
|
|
|
Sleep(3000);
|
|
|
|
|
menu();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//暗号错误,再次注册
|
|
|
|
|
else
|
|
|
|
|
printf("暗号错误,注册失败!\n\n");reenroll();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//继续注册
|
|
|
|
|
void reenroll()
|
|
|
|
|
{
|
|
|
|
|
printf("继续注册请按1:");
|
|
|
|
|
if(getch()==49)
|
|
|
|
|
enroll();
|
|
|
|
|
else
|
|
|
|
|
jiemian();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//登录
|
|
|
|
|
void login()
|
|
|
|
|
{
|
|
|
|
|
system("cls");
|
|
|
|
|
char zhanghao[20];
|
|
|
|
|
char mima[20];
|
|
|
|
|
char password2[20];
|
|
|
|
|
if((fp=fopen("manager.txt","rb"))==NULL){
|
|
|
|
|
printf("未查询到管理员账号\n请先注册,3秒后为您跳转到注册界面");
|
|
|
|
|
Sleep(3000);
|
|
|
|
|
enroll();
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
struct manager one;
|
|
|
|
|
printf("\n\t\t\t管理员账号:");
|
|
|
|
|
scanf("%s",zhanghao);
|
|
|
|
|
printf("\n\t\t\t管理员密码:");
|
|
|
|
|
ycmm();
|
|
|
|
|
while(!feof(fp)){
|
|
|
|
|
fscanf(fp,"%s%s",one.name,one.password);
|
|
|
|
|
if(!strcmp(zhanghao,one.name)&&!strcmp(mima_,one.password)){
|
|
|
|
|
printf("\n登录成功!\n");
|
|
|
|
|
n=1;
|
|
|
|
|
fclose(fp);
|
|
|
|
|
printf("3秒后进入管理员界面");
|
|
|
|
|
Sleep(3000);
|
|
|
|
|
menu();return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("\t\t\t登录失败!\n\n");
|
|
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
relogin();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//继续登录
|
|
|
|
|
void relogin()
|
|
|
|
|
{
|
|
|
|
|
printf("继续登录请按1,按其它任意键返回主界面:");
|
|
|
|
|
if(getch()==49)
|
|
|
|
|
login();
|
|
|
|
|
else
|
|
|
|
|
jiemian();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//隐藏密码
|
|
|
|
|
void ycmm()
|
|
|
|
|
{
|
|
|
|
|
int i=0;
|
|
|
|
|
for(;i<10;i++)
|
|
|
|
|
{
|
|
|
|
|
mima_[i]=getch();
|
|
|
|
|
if(mima_[i]=='\b')
|
|
|
|
|
{
|
|
|
|
|
if(i<=0)
|
|
|
|
|
printf(" "),i=1;
|
|
|
|
|
printf("\b \b");
|
|
|
|
|
i=i-2;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if(mima_[i]=='\r')
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
printf("*");
|
|
|
|
|
}
|
|
|
|
|
mima_[i]='\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//菜单
|
|
|
|
|
void menu()
|
|
|
|
|
{
|
|
|
|
|
int b=0;
|
|
|
|
|
do{
|
|
|
|
|
system("cls");
|
|
|
|
|
system("color f3");
|
|
|
|
|
int a;
|
|
|
|
|
b=0;
|
|
|
|
|
printf("\n\n\n\n\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: 7:退出 :\n");
|
|
|
|
|
printf("\t\t:--输入数 <1-7>选择功能--:\n\n");
|
|
|
|
|
scanf("%d",&a);
|
|
|
|
|
switch(a)
|
|
|
|
|
{
|
|
|
|
|
case 1: add(); break; //添加
|
|
|
|
|
case 2: search(); break; //查询
|
|
|
|
|
case 3: modify(); break; //修改
|
|
|
|
|
case 4: dele(); break; //删除
|
|
|
|
|
case 5: look(); break; //浏览
|
|
|
|
|
case 6: jiemian(); break; //退出
|
|
|
|
|
case 7: exit(0);
|
|
|
|
|
default: return;
|
|
|
|
|
}
|
|
|
|
|
printf("按1返回到管理员界面:");
|
|
|
|
|
b=getch();
|
|
|
|
|
}while(b==49);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//添加用户信息 1.新建
|
|
|
|
|
void add()
|
|
|
|
|
{
|
|
|
|
|
struct user one;
|
|
|
|
|
struct user one={'\0','\0','\0','\0','\0'};//初始化,防止文本里出现乱码
|
|
|
|
|
system("color e3");
|
|
|
|
|
if((fp=fopen("user.txt","ab"))==NULL)
|
|
|
|
|
{
|
|
|
|
@ -70,106 +256,99 @@ void add()
|
|
|
|
|
scanf("%s",one.tel2);
|
|
|
|
|
printf("\n请输入用户电子邮箱:");
|
|
|
|
|
scanf("%s",one.email);
|
|
|
|
|
fwrite(&one,sizeof(struct user),1,fp); //把数据块录入user.txt中
|
|
|
|
|
fprintf(fp,"%-8s%-15s%-15s%-15s%-20s\n",one.name,one.place,one.tel1,one.tel2,one.email);
|
|
|
|
|
fclose(fp);
|
|
|
|
|
printf("\n注册成功!\n");
|
|
|
|
|
system("pause");
|
|
|
|
|
menu();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//修改
|
|
|
|
|
void modify()
|
|
|
|
|
printf("\n添加成功!\n");
|
|
|
|
|
}
|
|
|
|
|
//查询 2.查询
|
|
|
|
|
void search()
|
|
|
|
|
{
|
|
|
|
|
struct user one;
|
|
|
|
|
char namekey[8];
|
|
|
|
|
printf("输入要查询的姓名:");
|
|
|
|
|
scanf("%s",namekey);
|
|
|
|
|
if((fp=fopen("user.txt","ab+"))==NULL) //打开文件
|
|
|
|
|
if((fp=fopen("user.txt","rb"))==NULL) //打开文件
|
|
|
|
|
{
|
|
|
|
|
printf("\n不能打开文件!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
int m=0,t=1;
|
|
|
|
|
t=0;
|
|
|
|
|
m=0;
|
|
|
|
|
while(!feof(fp))
|
|
|
|
|
{
|
|
|
|
|
fread(&user[m],sizeof(struct user),1,fp)==1; //读取结构体中一个用户信息
|
|
|
|
|
if(!strcmp(user[m].name,namekey)) //判断是否相同
|
|
|
|
|
offset=ftell(fp);
|
|
|
|
|
fscanf(fp,"%s%s%s%s%s\n",one.name,one.place,one.tel1,one.tel2,one.email);
|
|
|
|
|
if(!strcmp(one.name,namekey)) //判断是否相同
|
|
|
|
|
{
|
|
|
|
|
t=0; //若相同,则在后面if句中输出
|
|
|
|
|
t=1;
|
|
|
|
|
printf("%-8s%-15s%-15s%-15s%-20s\n",one.name,one.place,one.tel1,one.tel2,one.email); //若相同,则在后面if句中输出
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
m++;
|
|
|
|
|
}
|
|
|
|
|
if(t)
|
|
|
|
|
printf("未找到\n"),fclose(fp),system("pause"),menu();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("找到\n");
|
|
|
|
|
printf("姓名\t\t籍贯\t\t电话1\t\t电话2\t\t邮箱\n");
|
|
|
|
|
printf("%-8s\t",user[m].name);
|
|
|
|
|
printf("%-15s\t",user[m].place);
|
|
|
|
|
printf("%-15s\t",user[m].tel1);
|
|
|
|
|
printf("%-15s\t",user[m].tel2);
|
|
|
|
|
printf("%-20s\t",user[m].email);
|
|
|
|
|
}
|
|
|
|
|
printf("\n您想要修改哪条信息?\n\n1.姓名\t2.籍贯\t3.电话1\t4.电话2\t5.邮箱\t其它任意键.不修改"); //修改信息提示
|
|
|
|
|
int a; //修改的信息序号
|
|
|
|
|
scanf("%d",&a);
|
|
|
|
|
char *newname;
|
|
|
|
|
char nweplace[15];
|
|
|
|
|
char newtel1[15];
|
|
|
|
|
char newtel2[15];
|
|
|
|
|
char newemail[20];
|
|
|
|
|
switch(a)
|
|
|
|
|
{
|
|
|
|
|
case 1:scanf("%s",newname),strcpy(user[m].name,newname),printf("%s",user[m].name);break;
|
|
|
|
|
default:break;
|
|
|
|
|
}
|
|
|
|
|
printf("修改成功\n");
|
|
|
|
|
if(!t)
|
|
|
|
|
printf("未找到\n");
|
|
|
|
|
fclose(fp);
|
|
|
|
|
system("pause");
|
|
|
|
|
menu();
|
|
|
|
|
}
|
|
|
|
|
//查询
|
|
|
|
|
void search()
|
|
|
|
|
//修改 3.修改
|
|
|
|
|
void modify()
|
|
|
|
|
{
|
|
|
|
|
char namekey[8];
|
|
|
|
|
printf("输入要查询的姓名:");
|
|
|
|
|
scanf("%s",namekey);
|
|
|
|
|
if((fp=fopen("user.txt","r"))==NULL) //打开文件
|
|
|
|
|
int a;
|
|
|
|
|
char ch[10];
|
|
|
|
|
struct user one;
|
|
|
|
|
search();
|
|
|
|
|
if(t==1)
|
|
|
|
|
{
|
|
|
|
|
printf("\n不能打开文件!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
printf("请输入你想修改的信息:1.姓名 2.籍贯 3.电话1 4.电话2 5.邮箱\n"); //修改信息提示
|
|
|
|
|
scanf("%d",&a);
|
|
|
|
|
fp=fopen("user.txt","r+");
|
|
|
|
|
printf("请输入新信息:");
|
|
|
|
|
switch(a)
|
|
|
|
|
{
|
|
|
|
|
case 1: scanf("%s",one.name);fprintf(fp,"%-8s",one.name);break;
|
|
|
|
|
case 2: fseek(fp,offset+8,SEEK_SET);
|
|
|
|
|
scanf("%s",one.place);fprintf(fp,"%-15s",one.place);break;
|
|
|
|
|
case 3: fseek(fp,offset+23,SEEK_SET);
|
|
|
|
|
scanf("%s",one.tel1);fprintf(fp,"%-15s",one.tel1);break;
|
|
|
|
|
case 4: fseek(fp,offset+38,SEEK_SET);
|
|
|
|
|
scanf("%s",one.tel2);fprintf(fp,"%-15s",one.tel2);break;
|
|
|
|
|
case 5: fseek(fp,offset+53,SEEK_SET);
|
|
|
|
|
scanf("%s",one.email);fprintf(fp,"%-20s",one.email);break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
printf("修改成功\n");
|
|
|
|
|
}
|
|
|
|
|
int m=0,t=0;
|
|
|
|
|
while(!feof(fp))
|
|
|
|
|
}
|
|
|
|
|
//删除 4.删除
|
|
|
|
|
void dele()
|
|
|
|
|
{
|
|
|
|
|
char a;
|
|
|
|
|
for(;;)
|
|
|
|
|
{
|
|
|
|
|
fread(&user[m],sizeof(struct user),1,fp)==1; //读取结构体中一个用户信息
|
|
|
|
|
if(!strcmp(user[m].name,namekey)) //判断是否相同
|
|
|
|
|
{
|
|
|
|
|
t=1; //若相同,则在后面if句中输出
|
|
|
|
|
search();
|
|
|
|
|
if(t==1)
|
|
|
|
|
break;
|
|
|
|
|
else
|
|
|
|
|
printf("退出请按N,按其它任意键继续:");
|
|
|
|
|
a=getchar();
|
|
|
|
|
if(a=='n'||a=='N')
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
m++;
|
|
|
|
|
}
|
|
|
|
|
if(t)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(t==1)
|
|
|
|
|
{
|
|
|
|
|
printf("找到\n");
|
|
|
|
|
printf("姓名\t\t籍贯\t\t电话1\t\t电话2\t\t邮箱\n");
|
|
|
|
|
printf("%-8s\t",user[m].name);
|
|
|
|
|
printf("%-15s\t",user[m].place);
|
|
|
|
|
printf("%-15s\t",user[m].tel1);
|
|
|
|
|
printf("%-15s\t",user[m].tel2);
|
|
|
|
|
printf("%-20s\t",user[m].email);
|
|
|
|
|
fp=fopen("user.txt","r+");
|
|
|
|
|
fseek(fp,offset,SEEK_SET);
|
|
|
|
|
fprintf(fp,"\n%-8s%-15s%-15s%-15s%-20s\n","","","","","");
|
|
|
|
|
fclose(fp);
|
|
|
|
|
printf("删除成功!\n");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
printf("未找到\n");
|
|
|
|
|
fclose(fp);
|
|
|
|
|
system("pause");
|
|
|
|
|
menu();
|
|
|
|
|
}
|
|
|
|
|
//浏览
|
|
|
|
|
//浏览 5.浏览
|
|
|
|
|
void look()
|
|
|
|
|
{
|
|
|
|
|
struct user one;
|
|
|
|
|
char c;
|
|
|
|
|
if((fp=fopen("user.txt","r"))==NULL) //打开文件user.txt
|
|
|
|
|
{
|
|
|
|
@ -177,36 +356,16 @@ void look()
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
int m=0;
|
|
|
|
|
printf("%-8s%-15s%-15s%-15s%-20s\n","姓名","籍贯","电话1","电话2","邮箱");
|
|
|
|
|
while(!feof(fp))
|
|
|
|
|
{
|
|
|
|
|
if(fread(&user[m],sizeof(struct user),1,fp)==1)
|
|
|
|
|
fscanf(fp,"%s%s%s%s%s\n",one.name,one.place,one.tel1,one.tel2,one.email);
|
|
|
|
|
printf("%-8s%-15s%-15s%-15s%-20s\n",one.name,one.place,one.tel1,one.tel2,one.email);
|
|
|
|
|
m++;
|
|
|
|
|
}
|
|
|
|
|
int i;
|
|
|
|
|
printf("姓名\t\t籍贯\t\t电话1\t\t电话2\t\t邮箱\n");
|
|
|
|
|
for(i=0;i<m;i++)
|
|
|
|
|
{
|
|
|
|
|
printf("%-8s\t",user[i].name);
|
|
|
|
|
printf("%-15s\t",user[i].place);
|
|
|
|
|
printf("%-15s\t",user[i].tel1);
|
|
|
|
|
printf("%-15s\t",user[i].tel2);
|
|
|
|
|
printf("%-20s\t",user[i].email);
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
if(fclose(fp)) //关闭文件
|
|
|
|
|
{
|
|
|
|
|
printf("关闭文件失败!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
scanf("%c",&c);
|
|
|
|
|
printf("是否继续?(Y/N):");
|
|
|
|
|
scanf("%c",&c);
|
|
|
|
|
if(c=='y'||c=='Y')
|
|
|
|
|
menu();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//退出
|
|
|
|
|
void quit()
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|