试图弄清楚这个特殊的功能。我需要用punct []来扫描密码,看看它是否包含其中一个符号,但如果有的话,我需要它带回一个整数。我试过n = strlen(密码),但似乎没有用。这就是我到目前为止所拥有的。我也无法返回一个关于isalpha和isdigit的if语句的整数,它应该将密码传递给它。
char password[17] = { '\0' };
char punct[] = { '!','@','#','$','%','^','&','*','?','_', '\0' };
printf("Enter your test password: \n");
fgets(password, 15, stdin);
for (int j = 0; n = (strnlen(password)); j < n; j++) {
if (isalpha(password[j]) == true){
int b = 1;
printf(" Must consist of at least one number 0-9.\n");
}
}
for is digit我有类似的想法,但我需要它来贯穿数组的长度
if(isdigit(passwords)){
return 1;}
答案 0 :(得分:0)
使用255个无符号字符数组unsigned char flags[255]
的最佳方式。
然后将数组初始化一次:
1 = alpha
2 =数字
4 =符号
memset(flags,0,255*sizeof(short));
for(unsigned int i='A';i<='Z';i++) flags[i]=1;
for(unsigned int i='a';i<='z';i++) flags[i]=1;
for(unsigned int i='0';i<='9';i++) flags[i]=2;
flags[(unsigned char)'!']=4;
flags[(unsigned char)'@']=4;
flags[(unsigned char)'#']=4;
flags[(unsigned char)'$']=4;
flags[(unsigned char)'%']=4;
flags[(unsigned char)'^']=4;
flags[(unsigned char)'&']=4;
flags[(unsigned char)'*']=4;
flags[(unsigned char)'?']=4;
flags[(unsigned char)'_']=4;
然后运行测试:
short m_flags=0;
for(int i=0;i<strlen(password);i++)
m_flags|=flags[password[i]];
结果=:
if(m_flags & 1) //alpha present
if(m_flags & 2) //numerics present
if(m_flags & 4) //symbols present