Is this possible? The idea is typing a password and it being translated to asterisks on the fly- pretty much like a password field on HTML. I’ve written this code, but it converts the input AFTER the user presses enter, not while he/she is typing.
#include <stdio.h>
#include <string.h>
#include <iostream>
int main()
{
char password[11]; int i, j;
printf("Enter the password : ");
gets(password);
system("cls");
int str_len = (int)strlen(password);
printf("Enter the password : ");
for(i = 0;i<2;i++)
{
printf(" ");
for(j=0;j<str_len/2;j++)
{
printf("*");
}
}
system("PAUSE>nul");
}
If you do want to get some extra points from the teacher, you could look into the function
int getch()which does what you want. It is located in the header fileconio.h.Googling for getch should provide you with some info – MSDN and cplusplus.com are my favorite pages.