int login()
{
stUser currentUser,sysUser={'\0'};
loadUserInfor(&sysUser,"c:\\user.dat");
if(strlen(sysUser.name)==0)
{
printf("系统初始化(首次进入系统需设定用户名和初始密码):\n 设置系统用户名:“);
gets(sysUser.name);
printf("设置用户原始密码:”);
gets(sysUser.password);
saveUserInfor(sysUser,"c:\\user.dat");
}
printf("用户登录:\n");
printf("输入用户名:“);
gets(currentUser.name);
printf("用户密码:”);
gets(currentUser.password);
if(strcmp(currentUser.name,sysUser.name)==0&&
strcmp(currentUser.password,sysUser.password)==0)
return 1;
else
return 0;
}
/*从用户文件“user.dat"中读取用户信息*/
stUser * loadUserInfor(stUser * userInfor,char * filename)
{
FILE * fp=NULL;
fp=fopen(filename,"rb");
if(fp!=NULL)
{
fread(userInfor,sizeof(stUser),1,fp);
fclose(fp);
}
return userInfor;
}
{
stUser currentUser,sysUser={'\0'};
loadUserInfor(&sysUser,"c:\\user.dat");
if(strlen(sysUser.name)==0)
{
printf("系统初始化(首次进入系统需设定用户名和初始密码):\n 设置系统用户名:“);
gets(sysUser.name);
printf("设置用户原始密码:”);
gets(sysUser.password);
saveUserInfor(sysUser,"c:\\user.dat");
}
printf("用户登录:\n");
printf("输入用户名:“);
gets(currentUser.name);
printf("用户密码:”);
gets(currentUser.password);
if(strcmp(currentUser.name,sysUser.name)==0&&
strcmp(currentUser.password,sysUser.password)==0)
return 1;
else
return 0;
}
/*从用户文件“user.dat"中读取用户信息*/
stUser * loadUserInfor(stUser * userInfor,char * filename)
{
FILE * fp=NULL;
fp=fopen(filename,"rb");
if(fp!=NULL)
{
fread(userInfor,sizeof(stUser),1,fp);
fclose(fp);
}
return userInfor;
}