单击两次字母?

时间:2016-07-30 23:50:00

标签: c++

void password()
{
int i=0, j;
char str[30], ch;
gotoxy (23,10);
cout<< "Welcome to our project! \n";
delay (800);
gotoxy (23,11);
cout<< "Please enter the password = ";
while ((ch=getch())!=13)
{
ch=getch();
str[i]=ch;
i++;
clrscr();
gotoxy (20,20);
cout<< "Enter Password = ";
for (j=0; j<i; j++)
cout<< "*";
}
str[i]='\0';
if (strcmp(str,"script")!=0)
{
cout<< endl;
cout<< "Incorrect Password! \n";
cout<< "Access Denied! \n";
getche();
exit (0);
}
}

我做了一会儿,我遇到了一个问题。所以问题是,当我编译程序并运行它时,没有任何错误。唯一的问题是,当它要求我输入脚本的密码时,我必须按PREAR每个字母表一次并显示一次(例如,密码是TOLS,我必须像TTOOLLSS一样按下它,它显示为TOLS )。我该如何解决?

1 个答案:

答案 0 :(得分:2)

删除该行:

ch=getch();

因为你已经获得了该行中的字符:

while ((ch=getch())!=13)