Checking Password Problem in C++

Started by
2 comments, last by phil05 20 years ago
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;
	}
 
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]
Patrick
i dont know... why dont u just use strings?
FTA, my 2D futuristic action MMORPG
Oh yeah.. thanks.

This topic is closed to new replies.

Advertisement