//模拟密码登录方式
// 假定要密码长度不少于八位 不多于12位
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
#define LEN 12
int main(){
printf("input password,length between 8~12, if longer than 12, will be tranced.\n");
printf("密码遇到 空格键 tab键 或者回车键时会截断.\n");
char password[LEN+1];
memset(password,NULL,LEN+1); //要理解多置空一位的含义
int i=0;
char ch;
ch=getch();
while(isprint(ch) && ch!=' '){ //Ps 空格键也是isprint()为true的字符
password[i]=ch;
i++;
if(i==LEN)
break;
putchar('*');
ch=getch();
}
if(i<8)
printf("密码太短,安全性不足,请重试!\n");
printf("the password is: %s\n",password);
system("pause");
return 0;
}