im having major issues saving my TicTacToe game in C++.

it is mainly in the function to save the game.. im not sure also if the code is calling that function properly. il show the code.......:

{
                char save_or_not;
                cout<<"Would you like to save the game?"<<endl;
                cin>>save_or_not;
                if(save_or_not == 'y'|| save_or_not == 'Y')
                {
                    void Save_Game();
                    break;
                }
                else
                {
                    break;
                }
                .
                .
                .
                .
                .
void Game::Save_Game(char Board[3][3])
{
    int i;
	FILE *savegame = fopen("save.bin","w");
	for (i = 0; i < 3; i++)
    {
        fprintf(savegame,"%c %c %c\n", Board[i][0], Board[i][1], Board[i][2]);
    }
	fclose(savegame);
	cout<<"game saved";
}

note: Board is the array for the board.
 I am a beginner at C++ so any help in relation to this program i assure you i can thank enough. So thanks in advance.

Recommended Answers

All 7 Replies

>>void Save_Game();

This is not how to call a function.

Since your Save_Game takes an 2d array, you need call your function
like this :

Save_Game( gameBoard) ; //where gameBoard is the board of tic-tac-toe

have you any ideas on the save part?

have you any ideas on the save part?

Yes.

1) You need to save your game board
2) You need to save stats : wins, losses, draw games.

Then when you load it in, all you have to do is
fill your game board, and your stats variable.

Yes.

1) You need to save your game board
2) You need to save stats : wins, losses, draw games.

Then when you load it in, all you have to do is
fill your game board, and your stats variable.

anything in the way of code?

do you know how to open a file to save it.

do you know how to open a file to save it.

i think so..

i have
FILE *savegame = fopen("save.bin","w");

is that right..
by the way thanks for the help. and your patience i suppose.. not easy helpin us "amateurs"

Use ofstream to save a file. Read up a bit on it and tell me if you know
how to open a file for saving.

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.