#include <stdio.h>
#include <string.h>
#include <conio.h>
char * getpwd(char * s)
{
char c ;
int i , j , k ;
for(i = 0 , j = 0 , k = 0 ; ! i || ! j ;) {
printf("请输入密码 : ") ;
while(k < 6) {
c = getch() ;
if((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c >= '0' && c <= '9') {
if((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) i ++ ;
else j ++ ;
putchar('*') ;
s[k ++] = c ;
}
}
printf("\n") ;
if(! i || ! j) {
i = 0 ;
j = 0 ;
k = 0 ;
printf("抱歉,密码必须包含数字和字母,请重新输入。\n") ;
} else {
s[k] = '\0' ;
}
}
return s ;
}
int main(void)
{
char pwd[2][8] ;
if(! strcmp(getpwd(pwd[0]) , getpwd(pwd[1]))) printf("密码正确\n") ;
else printf("密码错误。\n") ;
}
|