c语言如何判断密码不同字符,C语言从文本文档读取字符串(用户名和密码验证)...
簡(jiǎn)單的從txt文檔中獲取用戶名和密碼并驗(yàn)證
#include
#include
int recog_pwd(char name[20],char pwd[20]);
void main()
{
int isok;
char *name = "osd";
char *pwd = "123";
if((recog_pwd(name,pwd))==1)
{
printf("user and pwd right\n");
}else printf("user not exist or password is wrong\n");
}
int recog_pwd(char name[20],char pwd[20])
{
int s;
FILE *fp1;
char str[20];
/*
*以只讀方式打開(kāi)文件
*read.txt格式為 :用戶名 密碼 (中間有一空格)無(wú)限循環(huán)
*/
if ((fp1=fopen("read.txt","r"))==NULL)
{
printf("cannot open file\n");
return 0;
}
/*
*判斷賬戶是否存在
*/
while(!feof(fp1))
{
fscanf(fp1,"%s",str);
if(strcmp(str,name)==0)
{
printf("the name :%s is ok\n",name);
fscanf(fp1,"%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(fp1);
return 0;
}
}
fscanf(fp1,"%s",str);
}
fclose(fp1);
return 0;
}
附錄:read.txt文本格式
qwe 345
asd 123
zxdc 4546
afgbc 123
deeerf 789we
gggggg 00012
總結(jié)
以上是生活随笔為你收集整理的c语言如何判断密码不同字符,C语言从文本文档读取字符串(用户名和密码验证)...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: linux中bash的功能主要有,Lin
- 下一篇: c语言初学者百题大战答案七,C语言百题大