#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
void beep(){
printf("\a");
}
int InputPass(char * prompt,char *buff,int maxLen){
int c,n=0;
int x= _wherex(),y= _wherey();
printf("%s: ",prompt);
*buff=0;
while(c=_getch()){
if(c==0xd) return n;
else if(c==8){
if(!n)
beep();
else{
printf("\b \b");
n--;
}
}
else if(c==0x1b){
break;
}
else{
if(!isprint(c)){
beep();
continue;
}
if(n<maxlen){>
buff[n]=c;
n++;
buff[n]=0;
printf("*");
}else{
beep();
}
}
}
return 0;
}
int main(){
char buff[20];
int n=InputPass("Enter password",buff,sizeof(buff));
printf("\n");
if(n==0){
printf("input canceled\n");
}else{
printf("password is '%s'\n",buff);
}
return 0;
}