Password input

I've been trying to make a program which involves checking if two inputted passwords match. However, it seems as though my program always says that the passwords do not match, even though they actually should.
Also, I'm only allowed to use TurboC++ for this project.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
cout<<" Enter a password.";
    cout<<endl;
    char pw[30];
    startover:  //goto label
    for(int p=0;p<30;p++)
    { pw[p]=getch();
    if(pw[p]==13)
    break;
      cout<<"*";
      }
	 
    cout<<"\nEnter password once more"<<endl;
    char pwc[30];
	    for(int pi=0;pi<30;pi++)
	   { pwc[pi]=getch();
	     if(pwc[pi]==13)
	      break;
	     cout<<"*";
	   }
    


In the above, if(strcmp(pw,pwc)==0) always executes the else statement. Please help me figure this out. Thank you!

There are numerous problem in this code, but most prominent that your character arrays are not null terminated, so strcmp does not know when it should stop comparing and compares random memory until mismatch is found.
Thank you for your reply! Now that this is fixed, could you please quickly run me through the other problems?
just use std::string
Topic archived. No new replies allowed.