C语言账号登陆问题
不知道错在哪里,没有报错,但是无法使用登陆功能。程序代码:
#include <stdio.h> #include <stdlib.h> typedef struct{ char name[10]; char ps[10]; int power; }Student; int main(){ FILE *fp=fopen("date.dat","wb"); Student show1[2]={{"tea","tea123",1},{"stu","stu123",0}}; Student tmps,show; char temp; char datafile[]="student",relogin; int i,success=0; if(fp!=NULL){ fwrite(show1,sizeof(Student),2,fp); fclose(fp); } printf("================================================\n"); printf(" 欢 迎 进 入 学 生 请 假 管 理 系 统\n"); printf("================================================\n"); again: printf("请输入用户名:"); scanf("%s",tmps.name); printf("请输入密码:"); while ((temp= getch ()) != '\r') { putchar ('*'); tmps.ps[i++]=temp; } if(tmps.ps[i-1]==' ') tmps.ps[i-1]='\0'; else tmps.ps[i]='\0'; fp=fopen("date.dat","rb"); if(fp==NULL){ printf("文件%s打不开\n",datafile); exit(1); } while(fread(&show,sizeof(Student),1,fp)!=0) { if((strcmp(tmps.name,show.name)==0)&&(strcmp(tmps.ps,show.ps)==0)) printf("登录成功!\n"); success=1; if(show.power==1){ printf("您是老师!"); } if(show.power==0){ printf("你是学生!"); } fclose(fp); } if(success==0) { printf("\n您输入的名字或密码有误,是否重新输入?(y/n)"); relogin=getche(); if((relogin=='y')||(relogin=='Y')) { printf("请再次输入名字和密码\n"); goto again; } else { printf("程序结束"); exit(0); } }return 0; }