【发布时间】:2010-09-23 10:40:44
【问题描述】:
这可能吗?这个想法是输入一个密码,然后它会被即时翻译成星号——就像 HTML 上的密码字段一样。我已经编写了这段代码,但它会在用户按下回车后转换输入,而不是在他/她输入时。
#include <stdio.h>
#include <string.h>
#include <iostream>
int main()
{
char password[11]; int i, j;
printf("Enter the password : ");
gets(password);
system("cls");
int str_len = (int)strlen(password);
printf("Enter the password : ");
for(i = 0;i<2;i++)
{
printf(" ");
for(j=0;j<str_len/2;j++)
{
printf("*");
}
}
system("PAUSE>nul");
}
【问题讨论】:
-
永远不要使用
gets()。 绝不! -
感谢先生的提醒。这就是我在各种书籍中读到的内容,但这段代码只是某种草图,我在一小时前创建的那个使用 getch() 将每个字符单独存储到字符数组中。 :D