读书人

大神帮小弟我看看有几个疑问

发布时间: 2012-05-01 12:48:58 作者: rapoo

大神帮我看看,有几个疑问
#include <stdio.h>
#include <string.h>

#define PASSWORD "XXXXXXX" //正确的密码

int verify_password(char *password)
{
int authenticated; //通过验证
char buff[8];

authenticated = strcmp(password,PASSWORD);//比较输入的字符和密码相符不,通过返回

strcpy(buff,password);

return authenticated;
}

int main()
{
int valid_flag = 0;
char password[1024];

while(1)
{
printf("Please input the password:\t");
scanf("%s",password);

if(!verify_password(password))
{
printf("Congratulations!You have pass the verification!\n");
break;
}
else
{
printf("Incorrect password!\n\n");
}
}

return 1;
}




在我输入 XXXXXXX 后(7个,大写),通过,但是在我输入 xxxxxxxx 后(8个,小写),也能通过,什么原因?
还有buff的作用,却掉他后密码也不正确?
第一个问题中,和 buff字符串的大小有关系么?

[解决办法]
为什么我在电脑实验没有出现你说的问题?
[解决办法]
我的电脑里也没问题。。。再仔细看看
[解决办法]
运行通过没问题
[解决办法]
同0异非0,应该没什么问题!
[解决办法]
gcc,没问题

C/C++ code
jimmy@MyPet:~/code/learnc$ makegcc -Wall -g -o test test.c -std=c99test.c: In function ‘main’:test.c:20:7: warning: unused variable ‘valid_flag’ [-Wunused-variable]jimmy@MyPet:~/code/learnc$ ./test Please input the password:    xxxxxxxxIncorrect password!Please input the password:    xxxxxxxIncorrect password!Please input the password:    XXXXXXXCongratulations!You have pass the verification! 

读书人网 >C语言

热点推荐