关于Linux终端回显问题
来源:互联网 发布:金蝶软件 编辑:程序博客网 时间:2024/06/03 14:30
我们都知道,在Linux中:
char a[10] = {0};
scanf(”%s”, a);
在终端控制台上输入的字符串(或者字符)都会在终端显示出来,那么当我们想输入密码时(并不想被别人看见)该怎么办呢?
(可以退格重新输入密码哦)
/***************************************************************
File Name: mima.c
Author: 浮生流年
Function List: main() 主函数
Created Time: 2017年12月12日 星期二 13时37分13秒
**************************************************************/
#include <stdio.h>#include <termios.h>#include <unistd.h>int mygetch(){ struct termios oldt, newt; int ch; tcgetattr(STDIN_FILENO, &oldt); newt = oldt; newt.c_lflag &= ~(ICANON | ECHO); tcsetattr(STDIN_FILENO, TCSANOW, &newt); ch = getchar(); tcsetattr(STDIN_FILENO, TCSANOW, &oldt); return ch;}
int getpasswd(char *passwd, int size){ int c, n = 0; do { c = mygetch(); if (c != '\n' && c != 'r' && c != 127) { passwd[n] = c; printf("*"); n++; } else if ((c != '\n' | c != '\r') && c == 127)//判断是否是回车或则退格 { if (n > 0) { n--; printf("\b \b");//输出退格 } } }while (c != '\n' && c != '\r' && n < (size - 1)); passwd[n] = '\0';//消除一个多余的回车 return n;}
int main(){ char passWord[20]; printf("请输入密码:\n"); getpasswd(passWord, 20); printf("\n"); printf("你输入的密码是:%s\n", passWord); return 0;}
阅读全文
0 0
- 关于Linux终端回显问题
- 关于LINUX系统netterm终端登陆乱码问题。
- 关于linux终端编码问题最终版—Securecrt下可用
- 关于linux终端的研究
- 关于linux终端的研究
- linux终端显示汉字问题
- Linux终端显示乱码问题
- linux终端中文乱码问题
- 终端关于”闪卡”问题的处理
- 关于重置ubuntu终端配色问题
- 关于linux终端下的清屏
- 关于Linux终端操作的快捷键
- Linux终端下解决中文乱码问题
- Linux系统字符终端自动登录问题
- CentOS Linux 远程终端ssh乱码问题
- CentOS Linux 远程终端ssh乱码问题
- 解决Linux终端乱码输入问题
- linux locale引发的终端输入问题
- BZOJ4827:[Hnoi2017]礼物 (FFT)
- Activity singleTask Intent传值收不到
- caffe安装过程中与protobuf相关的问题
- swift中UIActionSheet的使用
- BigDecimal ROUND_HALF_DOWN与ROUND_HALF_UP的区别
- 关于Linux终端回显问题
- APS 审核总结
- H
- Tree
- 在mysql binlog中查看原生的SQL语句
- 《20171126》
- 集成海康在线监控
- 在visual studio中使用mysql
- 【C++】工作中遇到的难点