密码判断,
大神们,怎么编一段程序来判断密码是纯数字或者纯英文呢,谢谢啦
希望对楼主有帮助
程序代码:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <windows.h>
#include <ctype.h>
#define N 8
int main(void) {
char str[N + 1] = {0}, *p = str;
int c, flag = 0;
puts("请输入密码...");
while((c = getch()) != '\r' && p < str + N) {
if(isalpha(c)) {
*p++ = c;
putchar('*');
} else if(isdigit(c)) {
*p++ = c;
putchar('*');
} else {
*p++ = c;
putchar('*');
}
}
printf("\n密码验证中... ");
for(c = 0; c < 3; c++) {
Sleep(200);
printf("... ");
}
printf("\n密码明文为: %s\t", str);
for(p = str; *p != 0; p++) {
if(isalpha(*p)) flag++;
else if(isdigit(*p)) flag--;
}
if(flag == strlen(str)) puts("纯字母");
else if(flag == -strlen(str)) puts("纯数字");
else puts("其它组合");
return 0;
}









