pass word

i have been testing a password entering to my program. I want to enter the pass word as "*" and compare the entered password with my given pass word. After that run the relevant function. This is the code I'm working on

void login(){

	clrscr();
    char un[25], ps[25], atype[25];
	int i,c; 
	
	gotoxy(20,15);
    cout<<"Username: ";
    cin>>un;
	
	gotoxy(20,16);
    cout<<"Password: ";
    for ( i = 0; i < 24 && (c = getch()) != '\r'; ++i ) {
     ps[i] = c;
     putch('*');
    }
	
	gotoxy(20,17);
    cout<<"Usertype: ";
    cin>>atype;

    if(!strcmp(un,"technician") && !strcmp(ps,"123") && !strcmp(atype,"technician")){
       technicianMenu();
    }
   
    else if(!strcmp(un,"sales") && !strcmp(ps,"123") && !strcmp(atype,"sales")){
       salesMenu();
    }
	else if(!strcmp(un,"jacob") && !strcmp(ps,"123") && !strcmp(atype,"owner")){
       jacobMenu();  
    }
    else{
	cout<<"Invalid User name  and password ";
    }
}



My problem is that it wont load the relevant menu as I want. If someone can help me with that, would be very thankful
any help ...
You need to add a '\0' to ps after you finished reading the password

Please use code tags (the tags you used are wrong): [code]Your code[/code]
See: http://www.cplusplus.com/articles/z13hAqkS/

coder777 (1814) Aug 8, 2012 at 2:20pm
You need to add a '\0' to ps after you finished reading the password

Please use code tags (the tags you used are wrong): Your code
See: http://www.cplusplus.com/articles/z13hAqkS/


thx for your kind reply.
sure i'll use [code] tags next time correctly.

I would be very thankful if you could show me exactly how to use '\0' as I am new to C programming ..
1
2
3
4
5
6
for ( i = 0; i < 24 && (c = getch()) != '\r'; ++i ) {
   ps[i] = c;
   putch('*');
}
//password readed (or too long, try to fix that)
ps[i] = '\0'; //terminating character. 
for ( i = 0; i < 24 && (c = getch()) != '\r'; ++i ) {
ps[i] = c;
putch('*');
}
//password readed (or too long, try to fix that)
ps[i] = '\0'; //terminating character.



ne555

thx for the help. It works fine.
Just so you know, you don't have to quote everything frm the post before you!
Topic archived. No new replies allowed.