0

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????

2
Contributors
1
Reply
3
Views
12 Years
Discussion Span
Last Post by Narue
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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.