Capturing what the user types
In my little text-based game, I prompt the user to type in the passphrase, "The ice is nice.". The following line of code was to kind of test if I could do it...
#include ''iostream.h''
#include ''string.h''
int main()
{
char NeedToType[80] = "The Ice Is Nice\n";
char UserType[80];
cout << "Type in the correct passphrase: ";
cin >> UserType;
if (UserType == NeedToType)
{
cout << "Very good!\n";
return 0;
}
else
{
cout << " Wrong!\n";
}
return 0;
}
of course, this doesn''t work. Anyhow, I need to find out how my program can capture what the user types, and depending on what the user types act differently. Can anyone help me on this?
Programming::~Fredric(const Annoy_Ance)
3D Math- The type of mathematics that'll put hair on your chest!
"if (UserType == NeedToType)" only compares the string''s adresses (a char[80] is in fact a pointer to the first char)... and of course, the 2 adresses will never be equal.
Use instead the strcmp function :
if (strcmp(UserType,NeedToType)==0) // strings equal
else //strings different
Use instead the strcmp function :
if (strcmp(UserType,NeedToType)==0) // strings equal
else //strings different
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement