#include#include #include #include #include //注册用户 用户登录 显示所有用户 退出系统 #define USER_MAX 100 enum { nosuo =1, suo =2, }; //用户名 密码 联系方式 是否锁定 typedef struct Id { char name[20]; char password[7]; char phone[30]; char lock; }Id; Id id[USER_MAX]; size_t cnt; size_t cnt_yz; //显示菜单。 void show_ml(void) { system("clear"); puts("***欢迎使用***"); puts("1.注册用户"); puts("2.用户登录"); puts("3.显示所有用户"); puts("4.退出系统"); } //获取指令 int get_cmd(char start,char end) { puts("==========================="); printf("请输入指令"); while(1) { int cmd =getch(); if(start <= cmd && cmd <= end) { printf("%cn",cmd); return cmd; } } } char* get_str(char* str,size_t size) { assert(NULL!=str && size>1); size_t len; while(1) { len = strlen(fgets(str,size,stdin)); if(1==len) printf("n输入不能为空,请重新输入:"); else break; } if('n' == str[len-1]) str[len-1] = ' '; else while('n' != getchar()); return str; } void show_msg(const char* msg,float sec) { printf(" 33[01;32m%s 33[00mn",msg); usleep(sec*1000000); } void anykey_continue(void) { puts("按任意键继续..."); getch(); } int name_query(char* str) { for(int i=0; i 0) { // 删除一位密码 i--; printf("b b"); } continue; } i++; printf("*"); } passwd[size-1] = ' '; printf("n"); return passwd; } //注册用户 void enroll(void) { if(cnt >= USER_MAX) { show_msg("注册的用户数已满,注册失败!",0.7); return; } printf("请设置用户名:"); get_str(id[cnt].name,sizeof(id[cnt].name)); if(0 <= name_query(id[cnt].name)) { show_msg("该用户名已存在,请重新输入!",0.7); return; } while(1) { char password_r[7]; printf("请设置用户密码:"); get_passwd(id[cnt].password,sizeof(id[cnt].password)); printf("请再次输入密码:"); get_passwd(password_r,sizeof(password_r)); if(0 == strcmp(password_r,id[cnt].password)) break; else printf("n输入错误,请重新输入nn"); } printf("请输入用户联系方式(电话/邮箱):"); get_str(id[cnt].phone,sizeof(id[cnt].phone)); id[cnt].lock='1'; cnt++; show_msg("注册成功!",0.7); } //输入密码 int goup_password(void) { char name_[20]; char password_[7]; int cnt_yz=cnt+1; while(1) { system("clear"); if(0 == cnt) { show_msg("还没有用户!",0.7); return 0; } printf("请输入用户名:"); scanf("%s",name_); while(1) { for(int i=0;i = cnt) { show_msg("当前无用户!",0.7); return 0; } for(int i=0;i 暑期编程PK赛 得CSDN机械键盘等精美礼品!



