密码需要一个字母和一个数字。下面的代码:C中的密码强度检测器不起作用
#include <ctype.h>
int main()
{
char password;
printf("Please enter a password.\n");
scanf("%c", &password);
if ((isalpha (password) && isdigit(password))){
printf("Your password is strong!\n");
} else {
printf("Your password is weak!");
}
return 0;
}
然而,当我编译它,它总是打印“您的密码是弱”,甚至当我在这两个字符和数字输入。怎么了?
到底是什么问题?正如@JonathonReinhart的回答所指出的,对于一个字符,测试总是会失败 - 它不能同时是字母和数字。更准确地说明你想用英文而不是C来达到目的。 –
你的应用程序只需输入第一个字符('scanf(“%c”')并检查该字符是否为'isalpha()'AND'isdigit() '我想你想要修改你的应用程序来读取输入的整个密码并检查,如果至少有一个字母和一个数字。 – RhinoDevel
请看[怎么问](http://stackoverflow.com/help/how这就像是一个调试家庭作业的请求。 – zhon