本人大一作品,适合初学者使用,利用优化登陆系统的构建来巩固C语言基础。具体为三个从简单到稍微复杂的登录系统:
第一版本
①第一个版本的登录系统十分简陋,只能在当次运行时进行登录和注册,再次运行时需要重新注册才可以登录,并不能实现隐藏密码的功能。
#define _CRT_SECURE_NO_WARNINGS 1#include #include #include struct zhanghu//用户信息储存{char name[20];char zhanghao[20];char mima[20];};int zhuce(struct zhanghu zh[],int m);//注册模块void denglu(struct zhanghu zh[],int m);//登录模块void menu(void);//菜单void again(struct zhanghu zh[], char l[]);//检测模块int main(void)//主程序{int m=0;int k;struct zhanghu zh[100];while (1){menu();printf("请选择服务:");scanf("%d",&k);switch (k){case 1:zhuce(zh, m);m++;printf("%d\n\n",m);break;case 2:denglu(zh, m);break;case 3:printf("谢谢使用!!!\n");exit(0);default:printf("不存在该服务!!!");break;}}return 0;}void menu(void)//菜单{printf("---------------------------------------\n");printf("1--- 创建新账户\n");printf("2--- 登录\n");printf("3 --- 退出系统\n");printf("---------------------------------------\n");}int zhuce(struct zhanghu zh[],int m)//注册模块{char d[20], e[20],l[20];printf("用户名:");scanf("%s",&l);again(zh,l);printf("账号:"); scanf("%s",&d);printf("\n");printf("密码");scanf("%s",&e);printf("\n");strcpy(zh[m].name, l);strcpy(zh[m].zhanghao,d);strcpy(zh[m].mima, e);printf("创建成功!\n");printf("%s\n%s\n", zh[m].mima, zh[m].zhanghao);m++;return m;}void denglu(struct zhanghu zh[], int m)//登录模块{int g, f, i;char d[20], e[20],n[20];printf("用户名:");scanf("%s",&n);printf("账号:");scanf("%s", &d);printf("\n");printf("密码");scanf("%s", &e);printf("\n");for (i = 0; i < 99; i++){if (strcmp(zh[i].name, n) == 0){g = strcmp(zh[i].zhanghao, d);f = strcmp(zh[i].mima, e);if ((g == 0)&& (f == 0) ){ printf("%s,欢迎回来!!!\n\n", zh[i].name); }else{printf("账号或密码错误!!!!\n\n");}}}}void again(struct zhanghu zh[], char l[])//检测模块{int i;char z[20];strcpy(z, l);for (i = 0; i < 99; i++){while (strcmp(zh[i].name, z) == 0){printf("该用户名已被注册!!!\n");i = 0;printf("用户名:");scanf("%s", &z);}}strcpy(l, z);}
第二版本
②第二个版本的登陆系统,将用户信息存储于TXT文件中,需要在目录中添加Users.txt文件,实现了对密码的隐藏,但是存在缺陷。
#define _CRT_SECURE_NO_WARNINGS 1#include #include #include #include #include #include typedef struct users//创建用户数据存储单元{charname[20];charzh[20];charmm[20];}A; void menu();//菜单voidstart(int math);//中转程序void zhuce();//注册模块void denglu();//登录模块int now = 1;int i;int main()//主程序{menu();return 0;}void menu()//菜单{int select=0;printf("\n\t\t\t++++++++++++++++++++++++\n\t\t\t+欢迎使用XX登录系统+\n\t\t\t++++++++++++++++++++++++\n");system("color 1F");//程序面板颜色while (now){system("cls");do {printf("\n******************菜单栏*****************\n");printf("\t\t*\t①登录*\n");printf("\t\t*\t②注册*\n");printf("\t\t*\t③退出系统\t\t*\n");printf("*****************************************\n");printf("\n");printf("\t\t请输入选项:[\t]\b\b\b");scanf("%d", &select);} while (select > 5 ||select < 1);start(select);}}void start(int math)//中转{switch (math){case 1:denglu();break;case 2:zhuce();break;case 3:printf("感谢您的支持!\n欢迎下次使用!");now = 0;exit(0);}}void zhuce()//注册模块{system("cls");char c[20];A a, b;FILE* fp;printf("\n\t\t欢迎来到注册界面!\n");Sleep(500);fp = fopen("Users.txt","r");fread(&b, sizeof(A), 1, fp);printf("\n\t\t请设置账号:[ \t\t ]\b\b\b\b\b\b\b\b\b\b\b\b\b");scanf("%s",&a.zh);while(1){if (strcmp(a.zh, b.zh)){if (!feof(fp)){fread(&b, sizeof(A), 1, fp);}else{break;}}else {printf("该账号已存在!!!");Sleep(1000);fclose(fp);return;}}int time = 2;do{printf("\t\t请设置密码:[ \t\t ]\b\b\b\b\b\b\b\b\b\b\b\b\b");i = 0;for (i = 0; i < 20; i++){a.mm[i] = _getch();if (a.mm[i] == '\r'){break;}else{printf("*");}}a.mm[i] = '\0';printf("\n");printf("\t\t请确认密码:[ \t\t ]\b\b\b\b\b\b\b\b\b\b\b\b\b");i = 0;for (i = 0; i = 0);}void denglu(){system("cls");A a,b;FILE* fp;printf("欢迎来到登录界面!");printf("账号:\n");scanf("%s",&b.zh);printf("密码:\n");i = 0;for (i = 0; i < 20; i++){b.mm[i] = _getch();if (b.mm[i] == '\r'){break;}else{printf("*");}}b.mm[i] = '\0';printf("\n");fp = fopen("Users.txt", "r");while (1){fread(&a, sizeof(A), 1, fp);//printf("%s %s %s\n",a.name,a.zh,a.mm);if (strcmp(b.zh,a.zh)==0){break;}else{if (!feof(fp)){fread(&a, sizeof(A), 1, fp);}else{printf("账号或密码错误!!!\n");fclose(fp);Sleep(1000);system("cls");return;}}}if (strcmp(b.mm, a.mm)==0){printf("%s,欢迎回来!!!\n",a.name);fclose(fp);Sleep(1000);system("cls");return;}else{printf("密码错误!!!\n");fclose(fp);Sleep(1000);system("cls");return;}}
第三版本
③第三个版本的登陆系统包含登录注册功能,改密找回功能,还具备管理员系统可以查看和修改用户信息,同样,可以实现隐藏密码的功能,但是存在缺陷。(需要在目录中创建Users.dat和guanliyuan.dat两个文件)
库文件
#define _CRT_SECURE_NO_WARNINGS 1#include #include #include #include #include #include
储存单元的创建
typedef struct users//创建用户数据存储单元{charname[20];//用户名charzh[20];//账号charmm[20];//密码charquestion[20];//问题(找回密码时使用)charanswer[20];//回答(找回密码时使用)}A;typedef struct guanliyuan//设置管理员账号{char glzh[20];//账号char glmm[20];//密码}guanliyuan;
创建函数
int jiancha();//检测是否注册管理员账号void chuangjianguanliyuan();//在使用前先创建管理员账号void menu();//菜单void guanlimenu();//管理员菜单voidstart(int math);//中转模块void guanlistart(int math);//管理系统中转模块void zhuce();//注册模块void denglu();//登录模块void gaimi();//改密模块void zhaohui();//找回模块void guanli();//管理模块void look();//查看模块void change();//修改用户模块void xiugai();//修改管理员账户模块
主程序
int now = 1;//循环时使用int i;//函数中的通用整型变量int main()//主程序{int canshu;canshu = jiancha();if (canshu==1){chuangjianguanliyuan();}menu();return 0;}
第一次使用时,注册管理员账号
int jiancha()//检测是否注册管理员账号{guanliyuan guanli;FILE* fp;fp = fopen("guanliyuan.dat","rb+");char first;first = fgetc(fp);if (first==-1){return 1;}else{return 0;}}void chuangjianguanliyuan()//在使用前先创建管理员账号{guanliyuan guanli;FILE* fp;fp = fopen("guanliyuan.dat", "rb+");char a[20], b[20];printf("\t\t请输入管理员账号:");scanf("%s", &a);printf("\n\t\t请输入管理员密码:");scanf("%s", &b);strcpy(guanli.glzh, a);strcpy(guanli.glmm, b);fwrite(&guanli,sizeof(guanliyuan),1,fp);fclose(fp);printf("\n\t\t注册成功!");Sleep(1000);return;}
菜单以及中转模块
void menu()//菜单{int select = 0;printf("\n\t\t\t++++++++++++++++++++++++\n\t\t\t+欢迎使用XX登录系统+\n\t\t\t++++++++++++++++++++++++\n");system("color 1F");//程序面板颜色while (now){system("cls");//每次循环开始时清屏do{system("cls");printf("\n******************菜单栏*****************\n");printf("\t\t*\t①登录*\n");printf("\t\t*\t②注册*\n");printf("\t\t*\t③修改密码*\n");printf("\t\t*\t④找回密码*\n");printf("\t\t*\t⑤退出系统*\n");printf("*****************************************\n");printf("\n");printf("\t\t请输入选项:[\t]\b\b\b");scanf("%d", &select);//} while (20221110>select > 6 || select 20221112);start(select);}}void start(int math)//中转{switch (math){case 1:denglu();break;case 2:zhuce();break;case 3:gaimi();break;case 4:zhaohui();break;case 5:printf("感谢您的支持!\n欢迎下次使用!");now = 0;exit(0);case 20221111:guanli();break;}}
注册模块
void zhuce()//注册模块{system("cls");char c[20];A a, b;FILE* fp;printf("\n\t\t欢迎来到注册界面!\n");Sleep(500);fp = fopen("Users.dat", "rb+");fread(&b, sizeof(A), 1, fp);printf("\n\t\t请设置账号:[ \t\t ]\b\b\b\b\b\b\b\b\b\b\b\b\b");scanf("%s", &a.zh);while (1)//检查是否已存在相同账号{if (strcmp(a.zh, b.zh)){if (!feof(fp)){fread(&b, sizeof(A), 1, fp);}else{break;}}else{printf("该账号已存在!!!");Sleep(1000);fclose(fp);return;}}int time = 2;do{printf("\t\t请设置密码:[ \t\t ]\b\b\b\b\b\b\b\b\b\b\b\b\b");i = 0;for (i = 0; i < 20; i++)//获取密码{a.mm[i] = _getch();if (a.mm[i] == '\r'){break;}else{printf("*");}}a.mm[i] = '\0';printf("\n");printf("\t\t请确认密码:[ \t\t ]\b\b\b\b\b\b\b\b\b\b\b\b\b");i = 0;for (i = 0; i = 0);}
登录模块
void denglu()//登录模块{system("cls");A a,b;printf("\n欢迎来到登录界面!\n");printf("账号:");scanf("%s", &b.zh);printf("\n密码:");i = 0;for (i = 0; i < 20; i++)//获取密码{b.mm[i] = _getch();if (b.mm[i] == '\r'){break;}else{printf("*");}}b.mm[i] = '\0';printf("\n");FILE* fp = fopen("Users.dat", "rb+");//获取用户信息fread(&a, sizeof(A), 1, fp);while (1){if (strcmp(b.zh, a.zh)==0){break;}else{if (!feof(fp)){fread(&a, sizeof(A), 1, fp);}else{printf("账号错误!!!\n");Sleep(1500);fclose(fp);return;}}}fclose(fp);if (strcmp(b.mm, a.mm)==0 ){printf("%s,欢迎回来!!!\n", a.name);Sleep(1000);system("cls");return;}else{printf("密码错误!!!\n");Sleep(1000);system("cls");return;}}
改密模块
void gaimi()//改密模块{system("cls");A a, b;printf("欢迎来到改密界面!\n");printf("请输入账号:");scanf("%s", &b.zh);printf("\n请输入密码:");i = 0;for (i = 0; i < 20; i++){b.mm[i] = _getch();if (b.mm[i] == '\r'){break;}else{printf("*");}}b.mm[i] = '\0';printf("\n");FILE* pf = fopen("Users.dat", "rb+");fread(&a, sizeof(A), 1, pf);while (1){if (strcmp(b.zh, a.zh) == 0){break;}else{if (!feof(pf)){fread(&a, sizeof(A), 1, pf);}else{printf("账号错误!!!\n");Sleep(1500);fclose(pf);return;}}}if (strcmp(b.mm, a.mm) == 0){printf("%s,密码正确!!!\n", a.name);char c[20], d[20];int time = 2;do{printf("\t\t请设置新密码:[ \t\t ]\b\b\b\b\b\b\b\b\b\b\b\b\b");i = 0;for (i = 0; i < 20; i++){c[i] = _getch();if (c[i] == '\r'){break;}else{printf("*");}}c[i] = '\0';printf("\n");printf("\t\t请确认密码:[ \t\t ]\b\b\b\b\b\b\b\b\b\b\b\b\b");i = 0;for (i = 0; i = 0);}else{printf("\n密码错误!!!\n");Sleep(1000);system("cls");return;}}
找回模块(找回后可以改密)
void zhaohui()//找回密码模块{system("cls");A a, b;printf("欢迎来到登录界面!\n");printf("账号:");scanf("%s",b.zh);printf("\n");FILE* fp = fopen("Users.dat", "rb+");fread(&a, sizeof(A), 1, fp);while (1){if (strcmp(b.zh, a.zh) == 0){break;}else{if (!feof(fp)){fread(&a, sizeof(A), 1, fp);}else{printf("该用户不存在!!!\n");Sleep(1500);fclose(fp);return;}}}printf("问题:%s\n",a.question);printf("回答:");scanf("%s",b.answer);if (strcmp(b.answer, a.answer) == 0){printf("您的密码:%s\n", a.mm);printf("\n\n\n\n如要改密请按(1)\n返回请按任意键!!!\n");char fanhui;fanhui = _getch();if (fanhui == '1'){char c[20], d[20];int time = 2;do{printf("\n\t\t请设置新密码:[ \t\t ]\b\b\b\b\b\b\b\b\b\b\b\b\b");i = 0;for (i = 0; i < 20; i++){c[i] = _getch();if (c[i] == '\r'){break;}else{printf("*");}}c[i] = '\0';printf("\n");printf("\n\t\t请确认密码:[ \t\t ]\b\b\b\b\b\b\b\b\b\b\b\b\b");i = 0;for (i = 0; i = 0);}else{Sleep(300);return;}}}
管理员登录模块
void guanli()//管理员登录系统{system("cls");guanliyuan guanli;FILE* fp;fp = fopen("guanliyuan.dat", "rb+");fread(&guanli,sizeof(guanliyuan),1,fp);char c[20], d[20];printf("\t\t管理员账号:");scanf("%s",&c);printf("\n\t\t管理员密码:");scanf("%s",&d);if ((0 == strcmp(c, guanli.glzh)) && (strcmp(d, guanli.glmm) == 0)){guanlimenu();return;}else{printf("\t\t账号或密码错误!!!\n");Sleep(500);return;}}void guanlimenu()//管理员菜单{int select = 0;printf("\n\t\t\t++++++++++++++++++++++++\n\t\t\t+欢迎使用管理员系统+\n\t\t\t++++++++++++++++++++++++\n");system("color 1F");//程序面板颜色while (now){system("cls");do{system("cls");printf("\n******************菜单栏*****************\n");printf("\t\t*\t①查看用户信息*\n");printf("\t\t*\t②修改用户信息*\n");printf("\t\t*\t③修改管理员账户*\n");printf("\t\t*\t④退出系统*\n");printf("*****************************************\n");printf("\n");printf("\t\t请输入选项:[\t]\b\b\b");scanf("%d", &select);} while (select > 5 || select < 1);guanlistart(select);}}void guanlistart(int math)//中转{switch (math){case 1:look();break;case 2:change();break;case 3:xiugai();break;case 4:printf("感谢您的支持!\n欢迎下次使用!");Sleep(500);menu();break;}}
管理员功能模块(查看用户信息,修改用户信息,修改管理员账户)
void change()//修改用户信息{system("cls");A a,b;int number;char name[20];FILE* fp = fopen("Users.dat","rb+");fread(&a,sizeof(A),1,fp);printf("请输入要修改账号的用户名:\n");scanf("%s",&name);while (1){if (strcmp(a.name, name) == 0){break;}else{if (!feof(fp)){fread(&a, sizeof(A), 1, fp);}else {printf("该用户不存在!!!\n");fclose(fp);Sleep(500);return;}}}printf("\n%s\n%s\n%s\n",a.name,a.zh,a.mm);printf("请选择需要修改的项目:用户名(1),账号(2),密码(3)\n");scanf("%d",&number);while (1){switch (number){case 1:printf("新的用户名:");scanf("%s",b.name);strcpy(a.name,b.name);fseek(fp, -((int)(sizeof(A))), SEEK_CUR);fprintf(fp, "%s", a.name);printf("用户名修改成功!\n");Sleep(500);fclose(fp);Sleep(1500);return;case 2:printf("新的账号:");scanf("%s", b.zh);strcpy(a.zh, b.zh);fseek(fp, -((int)(sizeof(A) - 20)), SEEK_CUR);fprintf(fp, "%s", a.zh);printf("账号修改成功!\n");Sleep(500);fclose(fp);Sleep(1500);return;case 3:printf("新的密码:");scanf("%s", b.mm);strcpy(a.mm, b.mm);fseek(fp, -((int)(sizeof(A) - 40)), SEEK_CUR);fprintf(fp, "%s", a.mm);printf("密码修改成功!\n");Sleep(500);fclose(fp);Sleep(1500);return;}}}void xiugai()//修改管理员账号{guanliyuan guanli;FILE* fp;fp = fopen("guanliyuan.dat", "rb+");char a[20], b[20];printf("\t\t请输入新账号:");scanf("%s",&a);printf("\n\t\t请输入新密码:");scanf("%s", &b);strcpy(guanli.glzh, a);strcpy(guanli.glmm, b);fseek(fp, -((int)(sizeof(guanliyuan))), SEEK_CUR);fprintf(fp,"%s",guanli.glzh);fseek(fp, -((int)(sizeof(guanliyuan))-20), SEEK_CUR);fprintf(fp, "%s", guanli.glmm);fclose(fp);printf("\n\t\t修改成功!");Sleep(1000);return;}
完整代码
#define _CRT_SECURE_NO_WARNINGS 1#include #include #include #include #include #include typedef struct users//创建用户数据存储单元{charname[20];//用户名charzh[20];//账号charmm[20];//密码charquestion[20];//问题(找回密码时使用)charanswer[20];//回答(找回密码时使用)}A;typedef struct guanliyuan//设置管理员账号{char glzh[20];//账号char glmm[20];//密码}guanliyuan;int jiancha();//检测是否注册管理员账号void chuangjianguanliyuan();//在使用前先创建管理员账号void menu();//菜单void guanlimenu();//管理员菜单voidstart(int math);//中转模块void guanlistart(int math);//管理系统中转模块void zhuce();//注册模块void denglu();//登录模块void gaimi();//改密模块void zhaohui();//找回模块void guanli();//管理模块void look();//查看模块void change();//修改用户模块void xiugai();//修改管理员账户模块int now = 1;//循环时使用int i;//函数中的通用整型变量int main()//主程序{int canshu;canshu = jiancha();if (canshu==1){chuangjianguanliyuan();}menu();return 0;}int jiancha()//检测是否注册管理员账号{guanliyuan guanli;FILE* fp;fp = fopen("guanliyuan.dat","rb+");char first;first = fgetc(fp);if (first==-1){return 1;}else{return 0;}}void chuangjianguanliyuan()//在使用前先创建管理员账号{guanliyuan guanli;FILE* fp;fp = fopen("guanliyuan.dat", "rb+");char a[20], b[20];printf("\t\t请输入管理员账号:");scanf("%s", &a);printf("\n\t\t请输入管理员密码:");scanf("%s", &b);strcpy(guanli.glzh, a);strcpy(guanli.glmm, b);fwrite(&guanli,sizeof(guanliyuan),1,fp);fclose(fp);printf("\n\t\t注册成功!");Sleep(1000);return;}void menu()//菜单{int select = 0;printf("\n\t\t\t++++++++++++++++++++++++\n\t\t\t+欢迎使用XX登录系统+\n\t\t\t++++++++++++++++++++++++\n");system("color 1F");//程序面板颜色while (now){system("cls");//每次循环开始时清屏do{system("cls");printf("\n******************菜单栏*****************\n");printf("\t\t*\t①登录*\n");printf("\t\t*\t②注册*\n");printf("\t\t*\t③修改密码*\n");printf("\t\t*\t④找回密码*\n");printf("\t\t*\t⑤退出系统*\n");printf("*****************************************\n");printf("\n");printf("\t\t请输入选项:[\t]\b\b\b");scanf("%d", &select);//} while (20221110>select > 6 || select 20221112);start(select);}}void start(int math)//中转{switch (math){case 1:denglu();break;case 2:zhuce();break;case 3:gaimi();break;case 4:zhaohui();break;case 5:printf("感谢您的支持!\n欢迎下次使用!");now = 0;exit(0);case 20221111:guanli();break;}}void zhuce()//注册模块{system("cls");char c[20];A a, b;FILE* fp;printf("\n\t\t欢迎来到注册界面!\n");Sleep(500);fp = fopen("Users.dat", "rb+");fread(&b, sizeof(A), 1, fp);printf("\n\t\t请设置账号:[ \t\t ]\b\b\b\b\b\b\b\b\b\b\b\b\b");scanf("%s", &a.zh);while (1)//检查是否已存在相同账号{if (strcmp(a.zh, b.zh)){if (!feof(fp)){fread(&b, sizeof(A), 1, fp);}else{break;}}else{printf("该账号已存在!!!");Sleep(1000);fclose(fp);return;}}int time = 2;do{printf("\t\t请设置密码:[ \t\t ]\b\b\b\b\b\b\b\b\b\b\b\b\b");i = 0;for (i = 0; i < 20; i++)//获取密码{a.mm[i] = _getch();if (a.mm[i] == '\r'){break;}else{printf("*");}}a.mm[i] = '\0';printf("\n");printf("\t\t请确认密码:[ \t\t ]\b\b\b\b\b\b\b\b\b\b\b\b\b");i = 0;for (i = 0; i = 0);}void denglu()//登录模块{system("cls");A a,b;printf("\n欢迎来到登录界面!\n");printf("账号:");scanf("%s", &b.zh);printf("\n密码:");i = 0;for (i = 0; i < 20; i++)//获取密码{b.mm[i] = _getch();if (b.mm[i] == '\r'){break;}else{printf("*");}}b.mm[i] = '\0';printf("\n");FILE* fp = fopen("Users.dat", "rb+");//获取用户信息fread(&a, sizeof(A), 1, fp);while (1){if (strcmp(b.zh, a.zh)==0){break;}else{if (!feof(fp)){fread(&a, sizeof(A), 1, fp);}else{printf("账号错误!!!\n");Sleep(1500);fclose(fp);return;}}}fclose(fp);if (strcmp(b.mm, a.mm)==0 ){printf("%s,欢迎回来!!!\n", a.name);Sleep(1000);system("cls");return;}else{printf("密码错误!!!\n");Sleep(1000);system("cls");return;}}void gaimi()//改密模块{system("cls");A a, b;printf("欢迎来到改密界面!\n");printf("请输入账号:");scanf("%s", &b.zh);printf("\n请输入密码:");i = 0;for (i = 0; i < 20; i++){b.mm[i] = _getch();if (b.mm[i] == '\r'){break;}else{printf("*");}}b.mm[i] = '\0';printf("\n");FILE* pf = fopen("Users.dat", "rb+");fread(&a, sizeof(A), 1, pf);while (1){if (strcmp(b.zh, a.zh) == 0){break;}else{if (!feof(pf)){fread(&a, sizeof(A), 1, pf);}else{printf("账号错误!!!\n");Sleep(1500);fclose(pf);return;}}}if (strcmp(b.mm, a.mm) == 0){printf("%s,密码正确!!!\n", a.name);char c[20], d[20];int time = 2;do{printf("\t\t请设置新密码:[ \t\t ]\b\b\b\b\b\b\b\b\b\b\b\b\b");i = 0;for (i = 0; i < 20; i++){c[i] = _getch();if (c[i] == '\r'){break;}else{printf("*");}}c[i] = '\0';printf("\n");printf("\t\t请确认密码:[ \t\t ]\b\b\b\b\b\b\b\b\b\b\b\b\b");i = 0;for (i = 0; i = 0);}else{printf("\n密码错误!!!\n");Sleep(1000);system("cls");return;}}void zhaohui()//找回密码模块{system("cls");A a, b;printf("欢迎来到登录界面!\n");printf("账号:");scanf("%s",b.zh);printf("\n");FILE* fp = fopen("Users.dat", "rb+");fread(&a, sizeof(A), 1, fp);while (1){if (strcmp(b.zh, a.zh) == 0){break;}else{if (!feof(fp)){fread(&a, sizeof(A), 1, fp);}else{printf("该用户不存在!!!\n");Sleep(1500);fclose(fp);return;}}}printf("问题:%s\n",a.question);printf("回答:");scanf("%s",b.answer);if (strcmp(b.answer, a.answer) == 0){printf("您的密码:%s\n", a.mm);printf("\n\n\n\n如要改密请按(1)\n返回请按任意键!!!\n");char fanhui;fanhui = _getch();if (fanhui == '1'){char c[20], d[20];int time = 2;do{printf("\n\t\t请设置新密码:[ \t\t ]\b\b\b\b\b\b\b\b\b\b\b\b\b");i = 0;for (i = 0; i < 20; i++){c[i] = _getch();if (c[i] == '\r'){break;}else{printf("*");}}c[i] = '\0';printf("\n");printf("\n\t\t请确认密码:[ \t\t ]\b\b\b\b\b\b\b\b\b\b\b\b\b");i = 0;for (i = 0; i = 0);}else{Sleep(300);return;}}}void guanli()//管理员登录系统{system("cls");guanliyuan guanli;FILE* fp;fp = fopen("guanliyuan.dat", "rb+");fread(&guanli,sizeof(guanliyuan),1,fp);char c[20], d[20];printf("\t\t管理员账号:");scanf("%s",&c);printf("\n\t\t管理员密码:");scanf("%s",&d);if ((0 == strcmp(c, guanli.glzh)) && (strcmp(d, guanli.glmm) == 0)){guanlimenu();return;}else{printf("\t\t账号或密码错误!!!\n");Sleep(500);return;}}void guanlimenu()//管理员菜单{int select = 0;printf("\n\t\t\t++++++++++++++++++++++++\n\t\t\t+欢迎使用管理员系统+\n\t\t\t++++++++++++++++++++++++\n");system("color 1F");//程序面板颜色while (now){system("cls");do{system("cls");printf("\n******************菜单栏*****************\n");printf("\t\t*\t①查看用户信息*\n");printf("\t\t*\t②修改用户信息*\n");printf("\t\t*\t③修改管理员账户*\n");printf("\t\t*\t④退出系统*\n");printf("*****************************************\n");printf("\n");printf("\t\t请输入选项:[\t]\b\b\b");scanf("%d", &select);} while (select > 5 || select < 1);guanlistart(select);}}void guanlistart(int math)//中转{switch (math){case 1:look();break;case 2:change();break;case 3:xiugai();break;case 4:printf("感谢您的支持!\n欢迎下次使用!");Sleep(500);menu();break;}}void look()//查看用户信息{system("cls");FILE* fp = fopen("Users.dat","rb+");A a;fread(&a, sizeof(A), 1, fp);while (1){printf("%s\n%s\n%s\n\n",a.name,a.zh,a.mm);if (!feof(fp)){fread(&a, sizeof(A), 1, fp);}else{break;}}char fanhui;fanhui = _getch();if (fanhui == '\r'){Sleep(500);return;}}void change()//修改用户信息{system("cls");A a,b;int number;char name[20];FILE* fp = fopen("Users.dat","rb+");fread(&a,sizeof(A),1,fp);printf("请输入要修改账号的用户名:\n");scanf("%s",&name);while (1){if (strcmp(a.name, name) == 0){break;}else{if (!feof(fp)){fread(&a, sizeof(A), 1, fp);}else {printf("该用户不存在!!!\n");fclose(fp);Sleep(500);return;}}}printf("\n%s\n%s\n%s\n",a.name,a.zh,a.mm);printf("请选择需要修改的项目:用户名(1),账号(2),密码(3)\n");scanf("%d",&number);while (1){switch (number){case 1:printf("新的用户名:");scanf("%s",b.name);strcpy(a.name,b.name);fseek(fp, -((int)(sizeof(A))), SEEK_CUR);fprintf(fp, "%s", a.name);printf("用户名修改成功!\n");Sleep(500);fclose(fp);Sleep(1500);return;case 2:printf("新的账号:");scanf("%s", b.zh);strcpy(a.zh, b.zh);fseek(fp, -((int)(sizeof(A) - 20)), SEEK_CUR);fprintf(fp, "%s", a.zh);printf("账号修改成功!\n");Sleep(500);fclose(fp);Sleep(1500);return;case 3:printf("新的密码:");scanf("%s", b.mm);strcpy(a.mm, b.mm);fseek(fp, -((int)(sizeof(A) - 40)), SEEK_CUR);fprintf(fp, "%s", a.mm);printf("密码修改成功!\n");Sleep(500);fclose(fp);Sleep(1500);return;}}}void xiugai()//修改管理员账号{guanliyuan guanli;FILE* fp;fp = fopen("guanliyuan.dat", "rb+");char a[20], b[20];printf("\t\t请输入新账号:");scanf("%s",&a);printf("\n\t\t请输入新密码:");scanf("%s", &b);strcpy(guanli.glzh, a);strcpy(guanli.glmm, b);fseek(fp, -((int)(sizeof(guanliyuan))), SEEK_CUR);fprintf(fp,"%s",guanli.glzh);fseek(fp, -((int)(sizeof(guanliyuan))-20), SEEK_CUR);fprintf(fp, "%s", guanli.glmm);fclose(fp);printf("\n\t\t修改成功!");Sleep(1000);return;}