文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>在用户输入密码时回显号

在用户输入密码时回显号

时间:2007-06-27  来源:tianshanxue2005

在用户输入密码时回显号

            http://allweb.freehyperspace.com/tech/getpass.html

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>

/* Use this variable to remember original terminal attributes. */

struct termios saved_attributes;

    void
reset_input_mode (void)
{
    tcsetattr (STDIN_FILENO, TCSANOW, &saved_attributes);
}

    void
set_input_mode (void)
{
    struct termios tattr;
    char *name;

    /* Make sure stdin is a terminal. */
    if (!isatty (STDIN_FILENO))
    {
        fprintf (stderr, "Not a terminal.\n");
        exit (EXIT_FAILURE);
    }

    /* Save the terminal attributes so we can restore them later. */
    tcgetattr (STDIN_FILENO, &saved_attributes);
    atexit (reset_input_mode);

    /* Set the funny terminal modes. */
    tcgetattr (STDIN_FILENO, &tattr);
    tattr.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */
    tattr.c_cc[VMIN] = 1;
    tattr.c_cc[VTIME] = 0;
    tcsetattr (STDIN_FILENO, TCSAFLUSH, &tattr);
}

    int
main (void)
{
    char c;

    set_input_mode ();

    while (1)
    {
        read (STDIN_FILENO, &c, 1);
        if (c == EOF || c == '\n')          /* C-d */
            break;
        else
        {
            putchar('*');
            fflush(NULL);
        }
    }

    return EXIT_SUCCESS;
}
排行榜 更多 +
冰封前线1941无限金币版

冰封前线1941无限金币版

策略塔防 下载
头文字d公路传说手机版

头文字d公路传说手机版

模拟经营 下载
火车站模拟器手机版

火车站模拟器手机版

模拟经营 下载