I have been trying to code to manipulate string. I am making a program that would ask the user to enter a password but it will not display the actual string that are typed in, instead it should display '*'. I have this code that I've created but I guess this is wrong. so I need your advice when it comes to my coding. Language is C and compiler is Turbo C++ 3.0
Code:
#include <ctype.h>
#include <stdio.h>
#include <conio.h>
int main( void )
{
char ch[100];
int counter;
clrscr();
gotoxy( 25, 5 );printf( "Enter Password: " );
for( counter = 0; counter < 100; )
{
ch[ counter ] = getch();
if( ch[ counter ] == '\r' ) break;
if( isalpha( ch[ counter ] ) )
{
ch[ counter ] = '*';
printf( "%c", ch[ counter ] );
}
counter++;
}
getch();
return 0;
}