Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 密码字段中显示的额外字母_C++_Borland C++ - Fatal编程技术网

C++ 密码字段中显示的额外字母

C++ 密码字段中显示的额外字母,c++,borland-c++,C++,Borland C++,如果有人能帮助我,我将不胜感激。I已在循环结束时递增。解决此问题的最简单方法是将密码初始化为零 Enter new Username: anzam Enter new Password: ****** //entered azeez but the first * is already there in command box without user inputting anything Mazeez //displaying newPassword charnewpassword[20]

如果有人能帮助我,我将不胜感激。

I
已在循环结束时递增。解决此问题的最简单方法是将
密码
初始化为零

Enter new Username: anzam
Enter new Password: ****** //entered azeez but the first * is already there in command box without user inputting anything

Mazeez //displaying newPassword
charnewpassword[20];
memset(新密码,0,20);
对于(i=0;i<10;)
{
int c=getch();
如果(c==13)
打破
//检查字符是否有效
如果(c)继续;
如果(c>“~”)继续;
newPassword[i]=c;

cout一个问题可能是您将
conio
getch
)和
iostream
cin
)混合在一起,它们可能无法同步。请尝试在程序开头添加此行:

char newPassword[20];
memset(newPassword, 0, 20);

for (i = 0; i < 10; )
{
    int c = getch();
    if (c == 13)
        break;

    //check if character is valid
    if (c < ' ') continue;
    if (c > '~') continue;

    newPassword[i] = c;
    cout << "*";
    i++; //increment here
}

也可以看到密码,直到你看到代码< 13或代码>,但是,如果我没有错的话,在Windows中按下Enter生成第一个代码< 10 > /代码>然后是代码> 13 ,所以你可能要检查这两个都是一个停止条件。

循环条件<代码> II相信你看到的额外的是空白字符。你的实际字符是什么?如果您试图检查新密码数组,会得到什么?为了阅读的清晰性,我会将退格检查移动到循环中。对于(I=0;它的逗号可能应该更改为
&&
。请参阅:1)如果按下,则不会执行最后一个增量。
中断
立即跳出循环。2)在示例输出中,有问题的字符位于字符串的开头。谢谢@johnymopp,我想我现在已经修复了它,我应该远离这个:)@BarmakShemirani似乎已经完成了。谢谢!)
char newPassword[20];
memset(newPassword, 0, 20);

for (i = 0; i < 10; )
{
    int c = getch();
    if (c == 13)
        break;

    //check if character is valid
    if (c < ' ') continue;
    if (c > '~') continue;

    newPassword[i] = c;
    cout << "*";
    i++; //increment here
}
ios_base::sync_with_stdio ();