I am aware that it is not possible to echo the * while you type in standard ANSI C. But is there a way to display nothing while someone is typing their password in the conso
*This is not ANSI C (Thanks Billy) sample
You can detect keypress with _kbhit(), then get the value using _getch(). Both function will not echo the content on screen.
#include //For keyboard events
#include //Include this or iostream
#include
int main()
{
bool bContinue = true;
char szBuffer[255] = {0};
unsigned int nbufIndex = 0;
while (bContinue)
{
if (_kbhit())
{
szBuffer[nbufIndex] = _getch();
if (szBuffer[nbufIndex] == 0xD)
{
bContinue = false;
}
else
{
++nbufIndex;
printf("*");
}
}
}
printf("\n%s\n", szBuffer);
return 0;
}