// Checking Password
char TEMP_PASSWORD[7];
char PASSWORD[7] = "natale";
std::cout << "Enter Your Password: ";
std::cin.getline(TEMP_PASSWORD, 7, ''\n'');
if (TEMP_PASSWORD != PASSWORD)
{
std::cout << "Invalid." << std::endl;
}
else
{
std::cout << "Correct." << std::endl;
}
Checking Password Problem in C++
WTF is wrong with this?
quote:Original post by philvaira
WTF is wrong with this?// Checking Password char TEMP_PASSWORD[7]; char PASSWORD[7] = "natale"; std::cout << "Enter Your Password: "; std::cin.getline(TEMP_PASSWORD, 7, '\n'); if (TEMP_PASSWORD != PASSWORD) { std::cout << "Invalid." << std::endl; } else { std::cout << "Correct." << std::endl; }
Try using the strcmp() or strncmp() functions since you're using and array of characters to hold your passwords. You'll need to include cstring to use them.
syntax:
int strcmp(const char *str1, const char *str2);
int strncmp(const char *str1, const char *str2, size_t count);
Both return zero if the strings are equal.
[edited by - prh99 on March 27, 2004 3:38:41 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement