String comparison help

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

[CODE]
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;
}
[\CODE]
Neither pass nor p are null-terminated, so strcmp() is going to read off past the end of those "strings". I would recommend just using std::strings so you can use == to compare them.
Topic archived. No new replies allowed.