Hello
I'm having a problem with my program. What it does is take the input in 1 character at a time, replace it with a '*', and when enter is pressed, check to see if it is the correct password.
I have diagnosed the problem being with the strcat function. When it's commented out, the other code works fine. The program stops working after 2 characters are inputed. Thanks for your help!
Code:
#include <stdio.h>
#include <string.h>
int main()
{
char password[] = "cheese";
char input_pass[10] = "";
char c;
int t = 0;
int r;
printf("Enter password\n");
while(1)
{
c = getch();
if(c == 13)
break;
t++;
strcat(input_pass,&c); // THIS IS THE PROBLEM I THINK
gotoxy(t - 1, 1);
printf("*");
}
r = strcmp(password,input_pass);
if(r != 0)
{
printf("\n\nIncorrect password\n");
goto done;
}
printf("\n\nCorrect!\n");
done:
getchar();
return(0);
}