It will take alphanumeric input and display '*' on the screen. Backspace functionality is also there.
#include<stdio.h>
#include<conio.h>
int chk(int,int,int);
int main(void)
{ char c[20],ch;
int i=-1,k=0,x=0,y=0;
clrscr();
printf("Enter Passwo:");
x=wherex();
y=wherey();
do{
ch=getch();
if(ch=='\b')
{
if(chk(x,y,wherex()))
{
c[i]=' ';
--i;
}
}
else if(ch!='\r')
{
++i;
c[i]=ch;
putch('*');
}
}while(ch!='\r');
printf("\nPassword is:");
while(k<=i) {
printf("%c",c[k]);
k++;
}
getch();
return 0;
}
int chk(int xOriginal,int yOriginal,int xCurrent)
{
if(xOriginal==xCurrent)
return 0;
gotoxy(--xCurrent,yOriginal);
putch(' ');
gotoxy(xCurrent,yOriginal);
return 1;
}
#include<stdio.h>
#include<conio.h>
int chk(int,int,int);
int main(void)
{ char c[20],ch;
int i=-1,k=0,x=0,y=0;
clrscr();
printf("Enter Passwo:");
x=wherex();
y=wherey();
do{
ch=getch();
if(ch=='\b')
{
if(chk(x,y,wherex()))
{
c[i]=' ';
--i;
}
}
else if(ch!='\r')
{
++i;
c[i]=ch;
putch('*');
}
}while(ch!='\r');
printf("\nPassword is:");
while(k<=i) {
printf("%c",c[k]);
k++;
}
getch();
return 0;
}
int chk(int xOriginal,int yOriginal,int xCurrent)
{
if(xOriginal==xCurrent)
return 0;
gotoxy(--xCurrent,yOriginal);
putch(' ');
gotoxy(xCurrent,yOriginal);
return 1;
}
No comments:
Post a Comment