I am trying to make a C++ program that accepts a username and password from the user and matches it to the ones that are already stored in the variables. For the password, I am using the * (asterisk) character to appear instead of the actual characters for privacy.
#include <iostream.h>
#include <conio.h>
#include <dos.h>
#include <string.h>
void main(void) {
clrscr();
gotoxy(10,10);
cout << "Username: ";
gotoxy(10,12);
cout << "Password: ";
char name1[10] = {"Apple"};
char name2[10];
char pass1[10] = {"Orange"};
char pass2[10] = {""};
gotoxy(23,10);
cin >> name2;
gotoxy(23,12);
cout << pass2;
int i = 0;
char ch;
while ((ch = getch()) != '\r') {
putch('*');
pass2[i] = ch;
i++;
}
if (strcmp(name1, name2) == 0 && strcmp(pass1, pass2) == 0) {
clrscr();
gotoxy(40,10);
cout << "YES!!!";
} else {
clrscr();
gotoxy(40,10);
cout << "NO!!!";
}
}
The problem is when I try to use the backspace key on the keyboard, I doesn't delete the character, instead it adds more characters to the end of it. I can make it work by importing the C language's string.h library. But is there any way I can make it work by using the libraries that are already defined in the code without having to use the string.h library.