用C语言实现登入系统密码不回显

在LINUX下不能使用getch()函数来使密码不回显,因为在linux下没有conio.h库文件,去网上找到解决方法将其替换为curses.h,仍然没用

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(int argc,char* argv[]){
char a[10];
printf("输入一个字符串:");
scanf("%s",a);
printf("输入成功,该字符串为:%s 
",a);
return 0;
}
[ouyangxi@DESKTOP-QNJ4U2U flight]$ ./a.out
输入一个字符串:oyx
输入成功,该字符串为:oyx
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(int argc,char* argv[]){
    char a[10];
    printf("输入一个字符串:");
    system("stty -echo");
    scanf("%s",a);
    system("stty echo");
                printf("
");
    printf("输入成功,该字符串为:%s 
",a);

return 0;
[ouyangxi@DESKTOP-QNJ4U2U flight]$ gcc lizi.c
[ouyangxi@DESKTOP-QNJ4U2U flight]$ ./a.out
输入一个字符串:
输入成功,该字符串为:oyx

将scanf("%s",a);改为

system("stty -echo");

    scanf("%s",a);
    system("stty echo");

即将输入行没有回显。

但是还是没有达到使输入字符成为*的功能。

正是步行者,一步步登峰!

原文地址:https://www.cnblogs.com/ouyangmail/p/12781926.html