麻烦大神帮我看一下哪里出问题了
#include<stdio.h>#include<string.h>
void student();
void teacher();
void admin();
void login();
struct log_numpass
{
char num[20];
char password[20];
};
int main()
{
system("reset");
login();
}
//登录界面显示
void login()
{
while(1)
{int n;
printf("\n\n\n\n\n");
printf("\n\n\n\n\n");
printf ("\t _____________________\n ");
printf ("\t | |\n" );
printf ("\t | 1.学生登录 |\n" );
printf ("\t | 2.教师登录 |\n" );
printf ("\t | 3.管理员登录 |\n" );
printf ("\t | 4.退出登录 |\n" );
printf ("\t |_____________________|\n" );
printf("\n\n\n\n\n");
printf ("\t\t\t" );
printf("请选择登录方式\n");
scanf("%d",&n);
switch(n)
{
case 1:
student();
break;
case 2:
// teacher();
break;
case 3:
// admin();
break;
case 4:
return;
default:
printf("请重新输入\n");
login();}
}
}
void student()
{
int i;
struct log_numpass s[100];
struct log_numpass s1[100];
printf("请输入帐号:\n");
scanf("%s",s[0].num);
FILE *fp;
fp=fopen("stu_password.txt","r");
if (NULL == fp )
printf("open error\n");
for(i=0;i<5;i++)
fscanf(fp,"%s %s",s1[i].num,s1[i].password);
for(i=0;i<5;i++)
{
if(0==strcmp(s[0].num,s1[i].num))
{
printf("请输入密码:\n");
scanf("%s",s[0].password);
if (0==strcmp(s[0].password,s1[i].password))
printf("登录成功\n");
else
printf("密码错误\n");
printf("该用户不存在!\n");
}
}
}
我输入5后会无限循环,无论输入123都会重新进入登录界面