Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Checking Password Problem in C++

This topic is 5168 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
	}
 

Share this post


Link to post
Share on other sites
Advertisement
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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!