int readtxt(char user[15],char pwd[15])
{
int s;
FILE *fp;
char str[15];
/*
*以只读方式打开文件
*user.txt格式为 :用户名 密码 (中间有一空格)无限循环
*/
if ((fp1=fopen("user.txt","r"))==NULL)
{
printf("cannot open file\n");
return 0;
}
/*
*判断账户是否存在
*/
while(!feof(fp))
{
fscanf(fp1,"%s",str);
if(strcmp(str,user)==0)
{
printf("the username :%s is ok\n",user);
fscanf(fp,"%s",str);
if(strcmp(str,pwd)==0)
{
printf("the pwd :%s is ok\n",pwd);
return 1;
}else
{
printf("the pwd :%s is wrong\n",pwd);
fclose(fp);
return 0;
}
}
fscanf(fp,"%s",str);
}
fclose(fp1);
return 0;
}
C语言实现读取txt用户和密码实现登陆验证
猜你喜欢
转载自blog.csdn.net/luoshiyong123/article/details/107167532
今日推荐
周排行