码迷,mamicode.com
首页 > 其他好文 > 详细

实现输入回显*号的函数

时间:2018-10-21 00:54:13      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:strlen   函数   getc   font   while   pass   int   color   print   

/*
在用户输入密码的时候,往往都是回显*或者其他的隐藏字符,于是:
*/

#define MAXLEN 6
char passwd[MAXLEN+1]="";

char *GetPasswd() {
unsigned char c;
int i=0;
while((c=getch())!=‘\r‘) {
if(i<MAXLEN&&isprint(c)) {
passwd[i++]=c;
putchar(‘*‘);
} else if(i>0&&c==‘\b‘) {
--i;
putchar(‘\b‘);
putchar(‘ ‘);
putchar(‘\b‘);
}
}
putchar(‘\n‘);
passwd[i]=‘\0‘;
return passwd;
}

//****************将字符串转换成整形**************/
int Changechar(char *str) {
int num=0,k,len,j;
len=strlen(str);
for(; *str; str++) {
k=*str-‘0‘;
j=(--len);
while(j--)k*=10;
num+=k;
}
return num; //将字符型的密码转换成整型
}

实现输入回显*号的函数

标签:strlen   函数   getc   font   while   pass   int   color   print   

原文地址:https://www.cnblogs.com/vilicute/p/9823398.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!