资源描述:
《c语言实现注册登陆功能(两个模块).doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、typedefstruct{charuser[20];charcode[20];}USER;voidwrite()/*用户信息写入*/{if((fp=fopen(pe.user,"w"))==NULL){printf("tt文件打开失败");}if(fwrite(&pe,sizeof(USER),1,fp)!=1){printf("tt写入文件错误");}fclose(fp);}voidzhuce(){chartemp[20],txt[100],cha;inti=0;do{printf("t
2、ttt用户注册");printf("tt1.直接注册2.阅读用户手册");cha=getch();if(cha=='2'){if((fp=fopen("使用说明.txt","r"))==NULL){printf("tt打开失败");exit(0);}fread(txt,2,20,fp);printf("tt%s",txt);/*txt=fgets(txt,100,fp);printf("%s",txt);*/}printf("tt按任意键继续");getch();system
3、("cls");printf("tttt用户注册");printf("tt用户名:");scanf("%s",pe.user);printf("tt密码:");scanf("%s",pe.code);printf("tt确认密码:");scanf("%s",temp);if(strcmp(pe.code,temp)!=0)printf("tt两次密码不一致,请重新输入");}while(strcmp(pe.code,temp)!=0);fp=fopen(pe.user,"
4、r");if(fp==NULL){fp=fopen(pe.user,"w");if(fp==NULL){printf("t注册失败");exit(0);}else{system("cls");printf("t注册成功");write();judge=false;denglu();}}else{printf("t该用户名已存在");fclose(fp);printf("t继续注册?(Y/N)");if(getch()=='Y')returnzhuce();elsereturndeng
5、lu();}}voidwrite(){if(fwrite(&pe,sizeof(User),1,fp)!=1){printf("tt写入文件错误");exit(0);//写入错误则退出程序}}voiddenglu(){charu[20],c[20],temp[20];printf("tttt用户登录");printf("tt用户名:");scanf("%s",u);fp=fopen(u,"r+");temp[0]='0';if(fp==NULL){printf("tt用户不存
6、在,请注册");printf("tt1.注册2.重新登陆");temp[0]=getch();if(temp[0]=='1'){system("cls");zhuce();}elsereturndenglu();}do{if(judge=true)fread(&pe,sizeof(USER),1,fp);printf("tt密码:");scanf("%s",c);if(strcmp(pe.code,c)!=0){printf("tt密码错误(1.退出2.重新输入)");temp[0]=get
7、ch();printf("");if(temp[0]=='1'){fclose(fp);returnmain();}}}while(temp[0]=='2');readfile();getch();caozuo();}