zoukankan      html  css  js  c++  java
  • 用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");

    即将输入行没有回显。

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

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

  • 相关阅读:
    CentOS 7/8修改系统运行级别
    Sketchup 汇总
    [转]Ruby之类的真相
    [转]Ruby之代码块的迷思
    [转]ruby中的异常处理
    [转]ruby中Class的allocate
    [转]ruby中require和load的区别
    [转]ruby之方法查找
    [转]ruby之动态方法
    [转] ruby之对象体系
  • 原文地址:https://www.cnblogs.com/ouyangmail/p/12781926.html
Copyright © 2011-2022 走看看