This is a program where you input a password, and for each char it prints a *.
But when the user presses backspace, it erases the unechoed char that was inputed, but not the *.
#include <stdio.h>
char pass[10];
int count=0;
int main(void)
{
printf("Enter new password (10 characters max):");
while ( (pass[count++]=getch()) != '\r')
{
if(count > 10)
{
for (count=0; count<10; count++)
{
pass[count] = '\0';
}
printf("\n\nYour password is too long, enter it again:");
count = 0;
continue;
}
else
{
if (pass[count-1] == '\b' && count==1)
{
count=0;
continue;
}
else
{
if (pass[count-1] == '\b')
{
printf("\b");
count -= 2;
}
else
{
printf("*");
}
}
}
}
puts("\n\nYour new password is:");puts(pass);
printf("\n");
system("pause");
return 0;
}
So what should I do so it erases the * when the user presses backspace?