#include<string.h>
main()
{int cs=0
int pw=8888
int lr
printf('Please enter the password:)
scanf(%d,lr)
while(cs<3)
{if(lr=pw)
{printf('You are welcome!')
cs=3}
else
{printf('\nWrong passward!\n')
cs++
printf('Enter again:\n')
scanf(%d,lr)
}
if(lr!=pw)
{printf('You have entered three times! You are not welcom!')
}}
试一下吧!
#include <stdio.h>#define UC (1U<<1) // upper case
#define LC (1U<<2) // lower case
#define NUM (1U<<3) // 0-9
#define ALL (UC|LC|NUM)
int check(const char pass1[], const char pass2[])
{
const char *p = &pass1[0]
unsigned int flag = 0
if (strlen(pass1) <6 || strlen(pass1) >8)
{
printf("password length is 6 to 8.\n")
return 1
}
if (strcmp(pass1, pass2))
{
printf("the tow passwords are diffrence.\n")
return 2
}
while (*p)
{
if (*p >= 'a' &&*p <= 'z') flag |= LC
else if (*p >= 'A' &&*p <= 'Z') flag |= UC
else if (*p >= '0' &&*p <= '9') flag |= NUM
else
{
printf("in valid charactor: %c.\n", *p)
return 3
}
++p
}
if (flag == ALL) return 0
if ((flag &UC) == 0)
{
printf("lack of uppercase.\n")
}
if ((flag &LC) == 0)
{
printf("lack of lowercase.\n")
}
if ((flag &NUM) == 0)
{
printf("lack of number.\n")
}
return -1
}
int main(int argc, char *argv[])
{
char pass1[100]
char pass2[100]
do {
printf("input password:")
scanf("%s", pass1)
printf("repeat password:")
scanf("%s", pass2)
} while (check(pass1, pass2) != 0)
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)