Jump to content
  • Advertisement
Sign in to follow this  
counterrabbit

setName, getName from an array

This topic is 4840 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

//Classes

class cPerson
{
	char	*	m_szPersonName;
public:

	void	SetPersonName(char *PersonName){m_szPersonName =  PersonName;}
	char	*GetPersonName(){return m_szPersonName;}
}

class cPeople
{

	cPeople m_aPeopleArray[20];

public:

	void SearchPeople(char * PeopleName);



cPeople::cPeople(void)
{
	m_aPersonArray[0].SetPeopleName("Rik");
	m_aPersonArray[1].SetPeopleName("Adam");
}

cPeople::~cPeople(void)
{
}

void cPeople::SearchPeople(char * PerosonName)
{
	cPeople people;

	for(int i = 0; i < 20; i++)
	{
		if(stricmp(PersonName, m_aPeopleArray.GetPerosonName()) == 0)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

void cPerson::SetCPerson(char * PersonName)
{
	this->m_szPersonName	= PersonName;
}

//main

void main()
{

	cControl ProgramControl;
	
	while(true)
	{
		ProgramControl.Run();
	}

}



ok forget some spelling mistakes, ive changed the class as to not give away my real intentions of this program, anyway when i run this program which compiles i get a system.nullrefereceexception. ive researched it on the msdn but it makes no sense. . .whats wrong with my code, can anyone see any problems?

Share this post


Link to post
Share on other sites
Advertisement
Er, where's your ProgramControl, and where are you expecting all this setname/getname functionality to be called from?

Share this post


Link to post
Share on other sites
Use std::string instead of char * and all your problems will magically disappear. (Your error is that you're calling stricmp on an uninitialised char * as soon as you access m_aPeopleArray[2] and later entries.)

Enigma

Share this post


Link to post
Share on other sites
thanks for replys but the answer was simply set the array to 2, the pointer was going mad cos it was pointing tom the 3rd element that hadnt been inited

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!