|
/*愿我的编程路上有你 作者:孤峰*/ #include “stdio.h” #include “string.h” #include “stdlib.h”
void password(char *pass) { char password[20],inletter=NULL; int i=0; clrscr(); gotoxy(17,6); printf(“\n\t\tInput your password:”); while((i<20)&&(inletter!=’\r’)) { inletter=getch(); /*无回显输入*/ if(inletter==8) { if(i>0) {password[--i]=NULL; putchar(8); /*退格键*/ putchar(‘ ‘); /*以空格代替*/ putchar(8); } else putchar(7); /*没有任何字符的退格,响铃警告*/ } else if(inletter!=’\r’) { password[i++]=inletter; /*只要不是退格和回车就接受*/ putchar(‘*’); } else {password=NULL; break; /*密码输入完了,记得加个NULL到后面*/ } } if(strcmp(password,pass)!=0) {clrscr(); gotoxy(17,8); printf(“\n\t\tPassword is mistake Tow seconds to exit!”); sleep(2);exit(0); } else {printf(“\n\t\tPassword is OK! Welcome to come!”); sleep(3); } }
void main(void) {char *pass=”lingdlz”; /*初始密码可以改为其它的*/ password(pass); /*调用*/ } |