我现在正在学习C。
我一直在开发一个检查用户输入(密码资格)的程序。为了使密码被视为合格且相当强大,它需要至少具有以下项目列表中的一项:
- 大写字母;
- '$' 符号;
- 字母数字字符;
在我的程序中,我创建了三个整数变量来计算上述要求。
不幸的是,每当我输入“正确”版本的密码时,程序都会不断打印密码不合格。
请给我一个线索,我可能错在哪里。
//challenge:
//build a program that checks when user enters a password for an uppercase letter, a number, and a dollar sign.
//if it does output that password is good to go.
int main()
{
char passwordInput[50];
int alphaNumericCount = 0;
int upperCharacterCount = 0;
int dollarCount = 0;
printf("Enter you password:\n");
scanf(" %s", passwordInput);
//int charactersAmount = strlen(tunaString);
for (int i = 0; i < 49; i++){
//tunaString[i]
if( isalpha(passwordInput[i]) ) {
alphaNumericCount++;
//continue;
}else if( isupper(passwordInput[i]) ) {
upperCharacterCount++;
//continue;
}else if( passwordInput[i] == '$' ) {
dollarCount++;
//continue;
}
}
if( (dollarCount == 0) || (upperCharacterCount == 0) || (alphaNumericCount == 0) ){
printf("Your entered password is bad. Work on it!\n");
}else{
printf("Your entered password is good!\n");
}
return 0;
}