C 如何从控制台获取密码字符,但将其作为星号回显
我想知道如何使用C 如何从控制台获取密码字符,但将其作为星号回显,c,input,C,Input,我想知道如何使用 scanf, getch() 或者其他,在用户提供输入时,我希望屏幕显示: ****** 对于每个字符。如果您在Windows上,我认为您可以使用以下内容- #include <stdio.h> #include <conio.h> int main(){ char str[8]; int i=0; printf("Enter the password :\n"); while (i< 8){ s
scanf, getch()
或者其他,在用户提供输入时,我希望屏幕显示:
******
对于每个字符。如果您在Windows上,我认为您可以使用以下内容-
#include <stdio.h>
#include <conio.h>
int main(){
char str[8];
int i=0;
printf("Enter the password :\n");
while (i< 8){
str[i]=getch();
printf("*");
i++;
}
str[i]='\0';
return 0;
}
#包括
#包括
int main(){
char-str[8];
int i=0;
printf(“输入密码:\n”);
而(i<8){
str[i]=getch();
printf(“*”);
i++;
}
str[i]='\0';
返回0;
}
getch()
函数在类Unix系统上不太容易使用。(curses
或ncurses
库提供了一个函数getch()
,但您必须调用函数来正确设置终端,然后将其重置回已知状态。)您使用的是什么操作系统?