January 22, 2012

C program to Input and Show a Password


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;
}



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 :)

Related Posts :



Categories:

1 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Related Posts with Thumbnails