The task is simple. You need to devise a program so that when you type something, it does not gets displayed on the console screen, instead you need to print a character like *, &, $ there, (it could be anything you want). The fallowing program performs this task. It lets you input something and prints an * sign in the place of the entered character. You can run this program in Turbo C++.
So, here is the program
Code:
/*C program to Input and Show a Password*/
# include "conio.h"
# include "stdio.h"
int main()
{
char a[50];
int i,j;
for(i=0;i<50;i++)
{
a[i]=getch();
if(a[i]==13)
break;
else
printf("*");
}
printf("\n");
for(j=0;j<i;j++)
printf("%c",a[j]);
return 0;
}
# include "stdio.h"
int main()
{
char a[50];
int i,j;
for(i=0;i<50;i++)
{
a[i]=getch();
if(a[i]==13)
break;
else
printf("*");
}
printf("\n");
for(j=0;j<i;j++)
printf("%c",a[j]);
return 0;
}
If you want to understand the logic of the program, it is very simple, getch() function is used to take the input from the user but it does not displays it on screen, instead every time, we put a * on the screen.
And later we output your input string.
It is the screen shot of the output.
Hope you like the post, comment bellow for Query and Feedback :)
Categories:
c++
1 comments:
good, it's simple at all
Post a Comment