我想编写一个程序来检查密码中是否包含数字,大写和小写字母。但是,执行此代码时会出现关于“左值”的错误。是什么原因?
#include <stdio.h>
#include <string.h>
int main(void)
{
char passwd[99];
printf("make a password:");
gets_s(passwd,99);
int num_count = 0, up_count = 0, down_count = 0;
while(1)
{
for (int i = 0; passwd[i] != NULL; i++)
{
if ('0' <= passwd[i] && passwd[i] <= '9')
num_count++;
else if ('a' <= passwd[i] && passwd[i] <= 'z')
{
down_count++;
}
else if ('A' <= passwd[i] && passwd[i] <= 'Z')
{
up_count++;
}
}
if (num_count == 0 || up_count == 0 || down_count = 0)
printf("make the password again!");
else
{
break;
}
}
getch();
return 0;
}
答案 0 :(得分:1)
num_count == 0 || up_count == 0 || down_count = 0
应该是
num_count == 0 || up_count == 0 || down_count == 0
为解释该错误,您拥有的语句等效于以下内容:
( num_count == 0 || up_count == 0 || down_count ) = 0
在赋值的左侧可以找到一个表达式,称为左值,而在括号中的表达式不是有效的左值。