Please tell me how to input password by showing a * or other symbol on console instead of text in C.

Recommended Answers

All 3 Replies

You need some way of reading raw input with a non-standard solution such as getch. Then it's just a matter of handling backspaces cleanly as printing an asterisk for every printing character that you read is trivial.

please explain in a clear way

please explain in a clear way

That wasn't clear? What Naru is saying is that there is no way in standard ANSI C to do what you are asking. However, there are extensions to the standard that allow for exactly what you want.

For example, the getch() function (part of the POSIX standard) allows you to get a single byte character from the terminal. Of course, if you're going to use this, you'll need to make sure that you have a version of the curses library to link against.

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.