Dec 6, 2015 at 9:50am UTC
I compared two strings but i only get the 'true' condition..help please..TIA!
[code]
#include <iostream>
#include<conio.h>
using namespace std;
main()
{
char name[30],pass[10],conpass[10];
int i=0,d=0;
cout<<"Enter Account Name: ";
cin>>name;
cout<<"Enter Password: ";
pass[0]=_getch();
while(pass[i] =13)
{
i++;
cout<<"*";
pass[i]=_getch();
}
cout<<"\nConfirm Password:";
conpass[0]=_getch();
while(conpass[d]!=13)
{
d++;
cout<<"*";
conpass[d]=_getch();
}
if (strcmp(pass,conpass)!=0)
{
cout<<"\nRegistration complete!";
}
else
{
cout<<"\nTry again!";
}
system ("pause>0");
}
Last edited on Dec 6, 2015 at 12:08pm UTC
Dec 6, 2015 at 9:51am UTC
i always get a true value if i use ==, while the strcmp doesnt work..
Dec 6, 2015 at 9:57am UTC
while (pass[i] =13)
This makes no sense. What are you trying to do with this line of code?
Dec 6, 2015 at 10:20am UTC
am sorry @Moschops that was supposed to be pass[i]!=13
Last edited on Dec 6, 2015 at 10:20am UTC
Dec 6, 2015 at 10:51am UTC
if (strcmp(pw,conpass)!=0)
I see you're trying to compare conpass
and pw
. This is unfortunate, as pw
doesn't exist. You can only compare variables that exist.
Dec 6, 2015 at 11:01am UTC
sorry my bad..i chaged it now..
it alway says
[Error]'strcmp' was not declared in this scope.
Dec 6, 2015 at 11:11am UTC
You forgot to include the <cstring> header that defines this function. So the function isn't actually declared in your code and the compiler cannot find it.
Dec 6, 2015 at 11:23am UTC
it worked but it only returns the 'true' value..
Dec 6, 2015 at 12:43pm UTC
strcmp returns zero when the two strings are the same.