The idea
scanning a password entered by the user and showing **********
in place of P@$$w00r_D
explaining the code
inside a while
loop keep scanning the characters using getch()
and put them into an array password[]
, until the user press return
The Code
#include <stdio.h>
#include <conio.h>
#define TRUE 1
#define P_MAX 25
int main(int argc, char* argv[]) {
char password[P_MAX], ch;
int i = 0;
puts("Enter the password [MAX 25]: ");
while (TRUE) {
if (i < 0) {
i = 0;
}//end if
ch = getch();
if (ch == 13)//return
break;
if (ch == 8) // BACKSPACE
{
putch('b');
putch(NULL);//Overwrite that character by NULL.
putch('b');
i--;//Decrement Current Track of Character. (i)
continue;
}//end if
password[i++] = ch;
ch = '*';
putch(ch);
}//end while
printf("\nPassword Entered : %s", password);//test
getch();
return 0;
}//end main
Compiling on Unix machine
[ar.lnx@host Documents] $ gcc 115.c -o x
115.c:2:18: fatal error: conio.h: No such file or directory
compilation terminated.
[ar.lnx@host Documents] $
this code works fine on windows, but not in Unix. any help?