I'm building a tic tac toe game with a variable board size using class GameBoard and class GamePiece. The GamePieces have a char array, pName, for the player's name and a char pType for the piece (X or O).

the board is set up using a pointer to an array of pointers (**board).

My program crashes when I try to print the board to the screen after each move. Here's the code for the operator << overload and the code for my screen refresh...

Please help????

.h

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

>for (col; col < size; col++) {
You're half way there. Now, actually assign 0 to col instead of just evaluating whatever indeterminate value is already there.

I figured if I stared at it long enough, I'd miss something completely obvious!

Thank you! Sometimes another pair of eyes does wonders!

mt

I still crash on the following:

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;
}
pieces[row][col].pType = p1.pType;

I get an access violation - I'm sure it's because I'm using a pointer to an array of pointers (**pieces). I tried dereferencing and I get illegal redirection errors. I'm not really familiar with **, so I'm not sure what else to try. Any ideas???

>I get an access violation
Do I look like the postergirl for psychic friends? Rather than post the code you think is causing the problem, pare the entire program down to bare bones such that it still exhibits the problem and post that. At least then we won't play 20 questions with you giving me irrelevant information while I try to weedle something useful out of you so that I can help.

Ya know... if I wanted to be talked to like I'm 3, I'd move back home with my mother...

I thought this was a forum that I could go to for help, not abuse.

If you don't want to be treated like a child, stop acting like one. I will be happy to help you with this and any other problems you may have, but as I said, I'm not a mind reader. You have to help me to help you.

I'll find help elsewhere.

It's one thing to give help and guidance (even when people do things wrong) and another to give verbal abuse. I'm probably twice your age and don't appreciate your attitude. I'm completely new to this, so any guidance as far as processes, procedures, etc. is more than welcome, but snotty comments and degrading language is completely unecessary. I won't utilize this website again.

What a sad life you must live...

>I'll find help elsewhere.
You do that.

>It's one thing to give help and guidance (even when people do things wrong) and another to give verbal abuse.
When you've helped as many people as I have, then you can preach to me about how to do it. Some people, such as yourself, think I should be nice and run off to get help from nicer but less qualified individuals. Sometimes they even find their way back to me and I help them unlearn the bad habits that they were taught. On the other hand, the many that have stayed to listen to what I teach have had no compaints at all. My conclusion is that the problem is on your end, not mine.

>I'm probably twice your age
Age is irrelevant.

>and don't appreciate your attitude.
That's your problem.

>I won't utilize this website again
You're only hurting yourself. If you ever manage to step off of your high horse and pay attention to the world around you, you would discover that not only am I highly qualified to help you, I'm also willing. That's a surprisingly rare combination. If you can't see past any assumed insults then you won't learn anything, and you deserve precisely that.

>What a sad life you must live...
I like how people assume that I'm some pathetic soul with no friends just by reading a post or two on an online forum. :mrgreen:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.