C言語はそれぞれLinuxとwindowの入力が現れないことを実現します
7771 ワード
linux:
window:
#include
#include
int main(int argc, char *args[])
{
// getpass
//
//
char *password = getpass("Input your password : ");
//
printf("password = %s
", password);
return 0;
}
window:
#include
#include
#include
#include
int main() {
char input_pwd[50], ch;
char pwd[50] = "123456";
int index = 0 ;
int tryTime = 3;
while (tryTime--) {
index = 0;
printf("Input your password:");
while ((ch = _getch()) != '\r') {
if (ch == '\b' && index > 0) {
printf("\b \b"); // +\b
index--;
}
else if (ch != '\b') {
input_pwd[index++] = ch;
}
}
input_pwd[index] = '\0';
printf("
%s\t",input_pwd);
if (strcmp(input_pwd, pwd) == 0) {
printf(" ");
return 0;
}
else
printf(" ,
");
}
printf(" 3 ");
}