Want immediate help, please!

I am not able to compare two strings. Please help. The password part.
My aim is i give a default password say, 12345678; i then ask the user to enter the password. I want to compare both of them. I user id and password match return 0 else return -1. But here, i am getting negative value on string comparison even though default password and entered password are same. PLEASE HELP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int welcome()
{
double uid; double b=12345;
char p[8]={'1','2','3','4','5','6','7','8'};
char pass[8];
cout<<"Enter your 5 digit USER IDENTIFICATION NUMBER:\n";
cin>>uid;
cout<<"Enter Password:\n";
for(int h=0;h<8;h++)
{
pass[h]=getch();
cout<<"*";
}
int r;
r=(strcmp(p,pass));
cout<<r; //OUPUT OF string comparison-wanted to debug
if(uid==b && r==0)
return 0;
else
return -1;
}
You're doin' the hardest way.
1
2
3
4
5
6
7
bool welcome(string pass)
{
    string psw;
    getline(cin, pwd);
    if(psw == pass) return true;
    else return false;
}


Use as if(welcome("12345678")) ... .
Last edited on
Topic archived. No new replies allowed.