アイデア
ユーザーが入力したパスワードをスキャンし**********
、代わりに表示するP@$$w00r_D
コードの説明
ユーザーが押すまで、while
ループ内で文字をスキャンし続けgetch()
、それらを配列に入れますpassword[]
return
コード
#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
Unix マシンでのコンパイル
[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] $
このコードは Windows では問題なく動作しますが、Unix では動作しません。助けはありますか?