C语言密码比对有关问题,不胜感激
C语言密码比对问题,求高手指教,不胜感激。
password.txt 中存放的是abcde 运行程序,输入abcde strcmp(st,s)==0 为何判否??不判是??
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int main()
{
FILE * fp;
char str[6],st[6],s[6];
printf("输入登陆密码:\n");
gets(st);
if((fp=fopen("G:\\文本文档\\password.txt","r"))==NULL)
{ printf("不存在此文件!\n");
exit(0); }
if(fgets(str,9,fp)!=NULL)
{ strcpy(s,str);
printf("%s\n",s); }
if(strcmp(st,s)==0)
printf("%s\n",st);
else
printf("^^^\n");
fclose(fp);
puts(st);
return 0;
}
------解决方案--------------------
没有判断否啊
调试了是正确的
还有什么问题?
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
代码正确的。。。
password.txt 中存放的是abcde 运行程序,输入abcde strcmp(st,s)==0 为何判否??不判是??
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int main()
{
FILE * fp;
char str[6],st[6],s[6];
printf("输入登陆密码:\n");
gets(st);
if((fp=fopen("G:\\文本文档\\password.txt","r"))==NULL)
{ printf("不存在此文件!\n");
exit(0); }
if(fgets(str,9,fp)!=NULL)
{ strcpy(s,str);
printf("%s\n",s); }
if(strcmp(st,s)==0)
printf("%s\n",st);
else
printf("^^^\n");
fclose(fp);
puts(st);
return 0;
}
------解决方案--------------------
没有判断否啊
调试了是正确的
还有什么问题?
------解决方案--------------------
if(fgets(str,9,fp)!=NULL)
{ strcpy(s,str);
printf("[%s]\n",s);
if ('\n'==s[strlen(s)-1]) s[strlen(s)-1]=0;//去掉末尾的\n,如果有
printf("[%s]\n",s);
}
------解决方案--------------------
------解决方案--------------------
代码正确的。。。