Hi Guys

Is there any function in C which will help me make an input string
invisible while we are entering the input??

I mean similar to oracle login. when we type our oracle password
at dos prompt it is not visible.

My requirement precisely.
1) I want to read a persons login id and password.
2) when the person enters his password it should not be visible.

Please help me out.


Thanks in advance.

>2) when the person enters his password it should not be visible.
You need a way of reading raw input without echo. The most well known function that does this is getch, from <conio.h>, but I can't recommend that because I don't know what compiler you're using. You can search this forum for questions about inputting a password for details. I'm sure I've posted complete code at least a few times.

Not in standard C nor C++. It requires functions that are not part of the language, but some systems and compilers have enhancements that could allow it.

>2) when the person enters his password it should not be visible.
You need a way of reading raw input without echo. The most well known function that does this is getch, from <conio.h>, but I can't recommend that because I don't know what compiler you're using. You can search this forum for questions about inputting a password for details. I'm sure I've posted complete code at least a few times.

Well thaanks for the idea.
i am just a newbie.i wrote the following code. it is working. but i want to know if there is something better.

#include <stdio.h>
#include <conio.h>

int main()
{
    char str[20];
    char ch;
    int i = 0;
    printf("\n Please enter a string: ");
    while((ch = getch()) != '\r')
    {
         str[i] = ch;
         i++;
    }
    str[i] = '\0';
    printf("\n input string = %s", str);
    getch();
}

>but i want to know if there is something better.
Better how? You've got the basic idea, so any "bettering" would be adding fluffy features on top of the basics.

>but i want to know if there is something better.
Better how? You've got the basic idea, so any "bettering" would be adding fluffy features on top of the basics.

:) Well Thanks for your quick help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.