954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Please help with pointer to array of pointers

I have a pointer called **pieces that points to an array of class type GamePieces that contain members pName and pType. I am trying store values in pieces[row][col].pType and then print the pieces in a matrix. My program crashes on this line of code:

while (pieces[row][col].pType == 'X' || pieces[row][col].pType=='O') {


Here's the code for the function:

void GameBoard::AssignPlayer1(int row, int col, GamePiece& p1)
{
	while (pieces[row][col].pType == 'X' || pieces[row][col].pType=='O') {
		cout << "Space is already taken, try again" << endl;
		cout << "row: ";
		cin >> row;
		row -= 1;	
		cout << "column: ";
		cin >> col;
		col -= 1;	
		cout << endl << endl;
	}
	strcpy(&pieces[row][col].pType, &p1.pType); 
}


Here's my print to screen function and my operator overload:

void GameBoard::RefreshBoard()
{
	int row;
	int col;
	for (row=0; row < size; row++) {
		for (col=0; col < size; col++) {
			cout << &pieces[row][col].pType;
		}
		cout << endl;
	}
	cout << endl << endl;
}
ostream& operator<<(ostream& os, const GamePiece& p)
{
	os << " " << p.pType << " " << endl;
	return os;
}


??????? What's wrong????

M Tritt
Newbie Poster
20 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

>What's wrong????
You created a new thread when you have an existing thread with THE SAME QUESTION! That's what's wrong. And this thread is locked; please direct further replies to the original thread. Thank you.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You