I've created a program to input a password but while printing it it contains garbage value. What is the reason behind it and is there is any way to solve it.
#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<string.h>
usingnamespace std;
int main()
{
system("cls");
char un[20],c,pass[20];
int h;
cout << "Username : ";
ss:
gets_s(un);
h = strlen(un);
for (int a = 0; a < h; ++a)
{
if (un[a] == ' ')
{
cout << "!!!Error : Do not use space for your username.\nEnter again : ";
goto ss;
}
}
int u;
cout << "Password : ";
sss:
u = 0;
do
{
c=_getch();
system("cls");
cout << "Username : " << un << "\nPassword : ";
for (int i = 0; i <=u; ++i)
cout << "*";
if (c == ' ')
{
system("cls");
cout << "!!!Error : Do not use space for your password.\nEnter again : ";
goto sss;
}
else
pass[u]=c;
++u;
}while (c != 13);
// system("cls");
cout << "\nYour password : " ;
cout << pass;
_getch();
return 0;
}