zoukankan      html  css  js  c++  java
  • linux下输入密码不回显

    这几天在做一个登陆的程序,需要将输入的密码屏蔽掉,自己百度,找到了两种方法,先贴下第一种方法,

    1 #include<stdio.h>
    2 #include<unistd.h>
    3 int main()
    4 {
    5     char *password;
    6     password=getpass("input passwd");
    7     printf("password is %s
    ",password);
    8     return 0;
    9 }

    getpass函数不会将接受到的字符显示,此函数需要包含头文件unistd.h

    下面介绍第二种方法(这种方法我没有使用,大家可以试下)

    1 void psswd()
    2 {
    3       initscr();                                 //开启curses模式
    4       noecho();                             //echo() and noecho(),默认输入显示在终端;
    5        endwin();                            //关闭curses模式
    6 }

    这种方法需要包含头文件curses.h,有些电脑上面可能没有这个头文件需要安装,我用的是sudo apt-get install libncurses5-dev 这条指令,然后程序在gcc的时候,需要链接上该头文件,如 gcc test.c -o test -lcurses,OK

  • 相关阅读:
    3D标签云
    IntelliJ IDEA 13.1.1版本偶然的错误
    414. Third Maximum Number
    217. Contains Duplicate
    442.Find All Duplicates in an Array
    3D轮播图
    448. Find All Numbers Disappeared in an Array
    Beautifulsoup模块
    MySQL数据库
    常用模块
  • 原文地址:https://www.cnblogs.com/kingos/p/4512900.html
Copyright © 2011-2022 走看看