2 Player Battleships Game

Ok I'm a total scrub at C++ and need all the direction I can get.

I'm tasked with creating a 2-player Battleships game and so far have this code with the grid and asking the players to enter their 1 space boat positions.

I'm stuck on the next step of actually starting to play the game and having each player guess the ship co-ordinates.

Any help to head me in the right direction will be much appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*Battleships 
2018
*/

#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>

const int GRID_SIZE = 10;

const char EMPTY_CELL = '~';

const int NUMBER_OF_PIECES = 6;

struct player_t
{
    std::string name;
    char pieceBoard[GRID_SIZE][GRID_SIZE];
    char otherBoard[GRID_SIZE][GRID_SIZE];
    int numberOfPieces;
};

void initBoard(char board[][GRID_SIZE]);

void displayBoard(char board[][GRID_SIZE]);

void placePieces(std::string name, char board[][GRID_SIZE]);

void saveGame(player_t p1, player_t p2);

void loadGame(player_t *p1, player_t *p2);

player_t initPlayer(player_t p);

int main()
{
    player_t player1;
    player_t player2;
    player1 = initPlayer(player1);
    player2 = initPlayer(player2);
    saveGame(player1, player2);
    loadGame(&player1, &player2);
    displayBoard(player1.pieceBoard);
    displayBoard(player2.pieceBoard);
    return 0;
}

player_t initPlayer(player_t p)
{
    std::string name;
    std::cout << "enter your name: ";
    std::cin >> name;
    p.name = name;
    p.numberOfPieces = NUMBER_OF_PIECES;
    initBoard(p.pieceBoard);
    initBoard(p.otherBoard);
    std::cout << p.name << " your boards look like this:\n";
    displayBoard(p.pieceBoard);
    displayBoard(p.otherBoard);
    placePieces(p.name, p.pieceBoard);
    return p;
}

void initBoard(char board[][GRID_SIZE])
{
    for(int i = 0; i < GRID_SIZE; i++)
    {
        for(int j = 0; j < GRID_SIZE; j++)
        {
             board[i][j] = EMPTY_CELL;
        }
    }
}

void displayBoard(char board[][GRID_SIZE])
{
    std::cout << "? 0 1 2 3 4 5 6 7 8 9\n";
    for(int i = 0; i < GRID_SIZE; i++)
    {
        std::cout << i << " ";
        for(int j = 0; j < GRID_SIZE; j++)
        {
            std::cout << board[i][j] << " ";
        }
        std::cout << "\n";
    }
    std::cout << "\n\n";
}

void placePieces(std::string name, char board[][GRID_SIZE])
{
    int x = -1;
    int y = -1;
    std::cout << name << " it is time to place your pieces\n";
    for(int i = 0; i < NUMBER_OF_PIECES; i++)
    {
        std::cout << "Enter the x coordinate for your piece number " << (i + 1) << ": ";
        std::cin >> x;
        std::cout << "Enter the y coordinate for your piece number " << (i + 1) << ": ";
        std::cin >> y;
        board[x][y] = 'P';
        std::cout << "\t\tCurrent Status\n";
        displayBoard(board);
    }
}

void saveGame(player_t p1, player_t p2)
{
    std::ofstream gameFile("game.saved");
    if(!gameFile)
    {
        std::cout << "Game could not be saved! returning back to play the game\n";
        return;
    }
    gameFile << p1.name << std::endl;
    for(int i = 0; i < GRID_SIZE; i++)
    {
        for(int j = 0; j < GRID_SIZE; j++)
        {
            gameFile << p1.pieceBoard[i][j];
        }
        gameFile << std::endl;
    }
    for(int i = 0; i < GRID_SIZE; i++)
    {
         for(int j = 0; j < GRID_SIZE; j++)
        {
            gameFile << p1.otherBoard[i][j];
        }
        gameFile << std::endl;
    }
    gameFile << p1.numberOfPieces << std::endl;
    gameFile << p2.name << std::endl;
    for(int i = 0; i < GRID_SIZE; i++)
    {
        for(int j = 0; j < GRID_SIZE; j++)
        {
            gameFile << p2.pieceBoard[i][j];
         }
         gameFile << std::endl;
    }
    for(int i = 0; i < GRID_SIZE; i++)
    {
         for(int j = 0; j < GRID_SIZE; j++);
    }
    gameFile << std::endl;
    gameFile << p2.numberOfPieces << std::endl;
    gameFile.close();
    std::cout << "Saving game and quitting\n";
    std::exit(0);
}

void loadGame(player_t *p1, player_t *p2)
{
    std::ifstream gameFile("game.saved");
    if(!gameFile)
    {
        std::cout << "saved game could not be loaded\n program will now shutdown\n";
        std::exit(2);
    }
    gameFile >> p1->name;
    for(int i = 0; i < GRID_SIZE; i++)
    {
        for(int j = 0; j < GRID_SIZE; j++)
        {
            gameFile >> p1->pieceBoard[i][j];
        }
    }
    for(int i = 0; i < GRID_SIZE; i++)
    {
        for(int j = 0; j < GRID_SIZE; j++)
        {
            gameFile >> p1->otherBoard[i][j];
        }
    }
    gameFile >> p1->numberOfPieces;
    gameFile >> p2->name;
    for(int i = 0; i < GRID_SIZE; i++)
    {
        for(int j = 0; j < GRID_SIZE; j++)
        {
            gameFile >> p2->pieceBoard[i][j];
        }
    }
    for(int i = 0; i < GRID_SIZE; i++)
    {
        for(int j = 0; j < GRID_SIZE; j++)
        {
            gameFile >> p2->otherBoard[i][j];
         }
    }
    gameFile >> p2->numberOfPieces;
}
Well i guess you want to add an int to your player-t structure to keep track of the number of boats that are "alive"
1
2
3
4
5
6
7
8
struct player_t
{
    std::string name;
    char pieceBoard[GRID_SIZE][GRID_SIZE];
    char otherBoard[GRID_SIZE][GRID_SIZE];
    int numberOfPieces;
    int numerOfPiecesAlive;
};


then initialise it in your init function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
player_t initPlayer(player_t p)
{
    std::string name;
    std::cout << "enter your name: ";
    std::cin >> name;
    p.name = name;
    p.numberOfPieces = NUMBER_OF_PIECES;
    p.numberOfPiecesAlive = NUMBER_OF_PIECES;
    initBoard(p.pieceBoard);
    initBoard(p.otherBoard);
    std::cout << p.name << " your boards look like this:\n";
    displayBoard(p.pieceBoard);
    displayBoard(p.otherBoard);
    placePieces(p.name, p.pieceBoard);
    return p;
}


then the pseudocode would look something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
while (the number of pieces alive for player 1 is not 0 AND the number of pieces alive for player 2 is not 0)
{
     display board for player 1
     ask player 1 to enter guessed coordinates
     if (there's a 'P' at said coordinates on player 2's board)
     {
          display message saying a boat was hit
          remove the 'P' on player 2's board and put a 'X' instead
          player2.numberOfPiecesAlive --;
     }
     else
     {
          display message saying it was a miss
     }
     exactly the same as above for player 2
}

check who has no boats left
display who's the winner
end of game.



I hope this is what you were looking for and that this helps in any way
Last edited on
Getting there slowly, I haven't touched this stuff for like 10 years!

The pseudocode part confuses me a bit and the commands I'd need to put in to determine if a ship is hit or not -

1
2
3
display message saying a boat was hit
          remove the 'P' on player 2's board and put a 'X' instead
          player2.numberOfPiecesAlive --; 




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
while (the number of pieces alive for player 1 is not 0 AND the number of pieces alive for player 2 is not 0)
{
     display board for player 1
     ask player 1 to enter guessed coordinates
     if (there's a 'P' at said coordinates on player 2's board)
     {
          display message saying a boat was hit
          remove the 'P' on player 2's board and put a 'X' instead
          player2.numberOfPiecesAlive --;
     }
     else
     {
          display message saying it was a miss
     }
     exactly the same as above for player 2
}

check who has no boats left
display who's the winner
end of game.
If it is this that confuses you
1
2
3
          display message saying a boat was hit
          remove the 'P' on player 2's board and put a 'X' instead
          player2.numberOfPiecesAlive --;  


this is what I mean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//player one just chose x and y
if (player2.pieceBoard[chosenY][chosenX] == 'P')
	{
		cout << "\nHit a boat!":
		player1.otherBoard[chosenY][chosenX} = 'X';
		player2.pieceBoard[chosenY][chosenX] == 'X'
		player2.numberOfPiecesAlive -= 1;
	}
else
	{
		cout << "\nYou missed all the boats.."
		player1.otherBoard[chosenY][chosenX} = 'M'; //M for miss, or anything you like
	}
		


I hope this helps
Getting my head back into it slowly.

Stuck on the last while part that determines if the game is still going or finished. I'm figuring the code is going to take the numberOfPiecesAlive for p1 and p2 and if it's greater than 0 then keep going.

I'm getting this error now as I'm sure my code is horribly incorrect.

-

bs2.cpp: At global scope:
bs2.cpp:198:1: error: expected unqualified-id before 'while'
while(p1.numberOfPiecesAlive =>0 AND p2.numberOfPiecesAlive =>0)
^~~~~



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
while(p1.numberOfPiecesAlive =>0 AND p2.numberOfPiecesAlive =>0)
{
     //player one just chose x and y
if (player2.pieceBoard[chosenY][chosenX] == 'P')
	{
		cout << "\nHit a boat!":
		player1.otherBoard[chosenY][chosenX} = 'X';
		player2.pieceBoard[chosenY][chosenX] == 'X'
		player2.numberOfPiecesAlive -= 1;
	}
else
	{
		cout << "\nYou missed all the boats.."
		player1.otherBoard[chosenY][chosenX} = 'M'; //M for miss, or anything you like
	}
Last edited on
Sorry for the late reply, I was away for a few days.

Yes there is a problem with your while loop statement.

For logical connectors such as "and" "or" you don't simply use "AND" or "OR".
for "and" you use the operator "&&"
for "or" you use the operator "||"

so your while loop should look something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
while(p1.numberOfPiecesAlive =>0 && p2.numberOfPiecesAlive =>0) //Replace and by &&
{
     //player one just chose x and y
if (player2.pieceBoard[chosenY][chosenX] == 'P')
	{
		cout << "\nHit a boat!":
		player1.otherBoard[chosenY][chosenX} = 'X';
		player2.pieceBoard[chosenY][chosenX] == 'X'
		player2.numberOfPiecesAlive -= 1;
	}
else
	{
		cout << "\nYou missed all the boats.."
		player1.otherBoard[chosenY][chosenX} = 'M'; //M for miss, or anything you like
	}


Hope this helps.

Hugo.
Last edited on
also be aware of logic vs bit operations. & is bits, as in 0011 & 0000 is 0000, while x && y is a boolean true or false value. That is why the && is doubled, to differentiate between logical and bit operations. Do not confuse them as it will compile either way, but give very, very different answers!





Thanks for getting back to me guys, I made the suggested changes and now I'm getting these errors now when compiling with the above code that I changed.

1
2
3
4
5
6
7
8
bs2.cpp: In function 'player_t initPlayer(player_t)':
bs2.cpp:57:4: error: 'struct player_t' has no member named 'numberOfPiecesAlive'; did you mean 'numerOfPiecesAlive'?
  p.numberOfPiecesAlive = NUMBER_OF_PIECES;
    ^~~~~~~~~~~~~~~~~~~
bs2.cpp: At global scope:
bs2.cpp:198:1: error: expected unqualified-id before 'while'
 while(p1.numberOfPiecesAlive =>0 && p2.numberOfPiecesAlive =>0) //Replace and by &&
 ^~~~~
Last edited on
bs2.cpp:57:4: error: 'struct player_t' has no member named 'numberOfPiecesAlive'; did you mean 'numerOfPiecesAlive'?

You probably made a typo either in the variable you used in your code or in your structure definition 'numberOfPiecesAlive'/'numerOfPiecesAlive' there's a b missing in "number" for the second one.

Can you post your code? there seems to be something wrong before your while loop.
Last edited on
Hmmmm here's the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*Battleships 
2018
*/

#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>

const int GRID_SIZE = 10;

const char EMPTY_CELL = '~';

const int NUMBER_OF_PIECES = 6;

struct player_t
{
    std::string name;
    char pieceBoard[GRID_SIZE][GRID_SIZE];
    char otherBoard[GRID_SIZE][GRID_SIZE];
    int numberOfPieces;
	int numerOfPiecesAlive;
};

void initBoard(char board[][GRID_SIZE]);

void displayBoard(char board[][GRID_SIZE]);

void placePieces(std::string name, char board[][GRID_SIZE]);

void saveGame(player_t p1, player_t p2);

void loadGame(player_t *p1, player_t *p2);

player_t initPlayer(player_t p);

int main()
{
    player_t player1;
    player_t player2;
    player1 = initPlayer(player1);
    player2 = initPlayer(player2);
    saveGame(player1, player2);
    loadGame(&player1, &player2);
    displayBoard(player1.pieceBoard);
    displayBoard(player2.pieceBoard);
    return 0;
}

player_t initPlayer(player_t p)
{
    std::string name;
    std::cout << "enter your name: ";
    std::cin >> name;
    p.name = name;
    p.numberOfPieces = NUMBER_OF_PIECES;
	p.numberOfPiecesAlive = NUMBER_OF_PIECES;
    initBoard(p.pieceBoard);
    initBoard(p.otherBoard);
    std::cout << p.name << " your boards look like this:\n";
    displayBoard(p.pieceBoard);
    displayBoard(p.otherBoard);
    placePieces(p.name, p.pieceBoard);
    return p;
}

void initBoard(char board[][GRID_SIZE])
{
    for(int i = 0; i < GRID_SIZE; i++)
    {
        for(int j = 0; j < GRID_SIZE; j++)
        {
             board[i][j] = EMPTY_CELL;
        }
    }
}

void displayBoard(char board[][GRID_SIZE])
{
    std::cout << "? 0 1 2 3 4 5 6 7 8 9\n";
    for(int i = 0; i < GRID_SIZE; i++)
    {
        std::cout << i << " ";
        for(int j = 0; j < GRID_SIZE; j++)
        {
            std::cout << board[i][j] << " ";
        }
        std::cout << "\n";
    }
    std::cout << "\n\n";
}

void placePieces(std::string name, char board[][GRID_SIZE])
{
    int x = -1;
    int y = -1;
    std::cout << name << " it is time to place your pieces\n";
    for(int i = 0; i < NUMBER_OF_PIECES; i++)
    {
        std::cout << "Enter the x coordinate for your piece number " << (i + 1) << ": ";
        std::cin >> x;
        std::cout << "Enter the y coordinate for your piece number " << (i + 1) << ": ";
        std::cin >> y;
        board[x][y] = 'P';
        std::cout << "\t\tCurrent Status\n";
        displayBoard(board);
    }
}

void saveGame(player_t p1, player_t p2)
{
    std::ofstream gameFile("game.saved");
    if(!gameFile)
    {
        std::cout << "Game could not be saved! returning back to play the game\n";
        return;
    }
    gameFile << p1.name << std::endl;
    for(int i = 0; i < GRID_SIZE; i++)
    {
        for(int j = 0; j < GRID_SIZE; j++)
        {
            gameFile << p1.pieceBoard[i][j];
        }
        gameFile << std::endl;
    }
    for(int i = 0; i < GRID_SIZE; i++)
    {
         for(int j = 0; j < GRID_SIZE; j++)
        {
            gameFile << p1.otherBoard[i][j];
        }
        gameFile << std::endl;
    }
    gameFile << p1.numberOfPieces << std::endl;
    gameFile << p2.name << std::endl;
    for(int i = 0; i < GRID_SIZE; i++)
    {
        for(int j = 0; j < GRID_SIZE; j++)
        {
            gameFile << p2.pieceBoard[i][j];
         }
         gameFile << std::endl;
    }
    for(int i = 0; i < GRID_SIZE; i++)
    {
         for(int j = 0; j < GRID_SIZE; j++);
    }
    gameFile << std::endl;
    gameFile << p2.numberOfPieces << std::endl;
    gameFile.close();
    std::cout << "Saving game and quitting\n";
    std::exit(0);
}

void loadGame(player_t *p1, player_t *p2)
{
    std::ifstream gameFile("game.saved");
    if(!gameFile)
    {
        std::cout << "saved game could not be loaded\n program will now shutdown\n";
        std::exit(2);
    }
    gameFile >> p1->name;
    for(int i = 0; i < GRID_SIZE; i++)
    {
        for(int j = 0; j < GRID_SIZE; j++)
        {
            gameFile >> p1->pieceBoard[i][j];
        }
    }
    for(int i = 0; i < GRID_SIZE; i++)
    {
        for(int j = 0; j < GRID_SIZE; j++)
        {
            gameFile >> p1->otherBoard[i][j];
        }
    }
    gameFile >> p1->numberOfPieces;
    gameFile >> p2->name;
    for(int i = 0; i < GRID_SIZE; i++)
    {
        for(int j = 0; j < GRID_SIZE; j++)
        {
            gameFile >> p2->pieceBoard[i][j];
        }
    }
    for(int i = 0; i < GRID_SIZE; i++)
    {
        for(int j = 0; j < GRID_SIZE; j++)
        {
            gameFile >> p2->otherBoard[i][j];
         }
    }
    gameFile >> p2->numberOfPieces;
}

while(p1.numberOfPiecesAlive =>0 && p2.numberOfPiecesAlive =>0) //Replace and by &&
{
     //player one just chose x and y
if (player2.pieceBoard[chosenY][chosenX] == 'P')
	{
		cout << "\nHit a boat!":
		player1.otherBoard[chosenY][chosenX} = 'X';
		player2.pieceBoard[chosenY][chosenX] == 'X'
		player2.numberOfPiecesAlive -= 1;
	}
else
	{
		cout << "\nYou missed all the boats.."
		player1.otherBoard[chosenY][chosenX} = 'M'; //M for miss, or anything you like
	}
1
2
3
4
5
6
7
8
struct player_t
{
    std::string name;
    char pieceBoard[GRID_SIZE][GRID_SIZE];
    char otherBoard[GRID_SIZE][GRID_SIZE];
    int numberOfPieces;
    int numberOfPiecesAlive; //ADDED "B" to make "numer" into "number"
};


Your while function is out of any function. That might be why you're getting an error
Got it, silly me! That eliminates that but still having issues with the 'While' -

bs2.cpp:198:1: error: expected unqualified-id before 'while'
while(p1.numberOfPiecesAlive =>0 && p2.numberOfPiecesAlive =>0)
^~~~~

In this part of code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
while(p1.numberOfPiecesAlive =>0 && p2.numberOfPiecesAlive =>0)
{
     //player one just chose x and y
if (player2.pieceBoard[chosenY][chosenX] == 'P')
	{
		cout << "\nHit a boat!":
		player1.otherBoard[chosenY][chosenX} = 'X';
		player2.pieceBoard[chosenY][chosenX] == 'X'
		player2.numberOfPiecesAlive -= 1;
	}
else
	{
		cout << "\nYou missed all the boats.."
		player1.otherBoard[chosenY][chosenX} = 'M'; //M for miss, or anything you like
	}
When you read a post here, you need to read *all* of it, not just the first few lines.
Agreeing with MikeyBoy

Your while function is out of any function. That might be why you're getting an error


:)
Ok, I guess I should have been more specific.

What you mean by 'out of any function'
Well your while loop is like such:

1
2
3
4
5
6
7
8
    int main(){}
    void initBoard(char board[][GRID_SIZE]){}
    void displayBoard(char board[][GRID_SIZE]){}
    void placePieces(std::string name, char board[][GRID_SIZE]){}
    void saveGame(player_t p1, player_t p2){}
    void loadGame(player_t *p1, player_t *p2){}

    //WHILE LOOP HERE 


you can either make a function and include it in like so:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void function(agruments...)
{
	while(p1.numberOfPiecesAlive =>0 && p2.numberOfPiecesAlive =>0) //Replace and by &&
	{
	     //player one just chose x and y
	if (player2.pieceBoard[chosenY][chosenX] == 'P')
		{
			cout << "\nHit a boat!":
			player1.otherBoard[chosenY][chosenX} = 'X';
			player2.pieceBoard[chosenY][chosenX] == 'X'
			player2.numberOfPiecesAlive -= 1;
		}
	else
		{
			cout << "\nYou missed all the boats.."
			player1.otherBoard[chosenY][chosenX} = 'M'; //M for miss, or anything you like
		}
		
	return;
}


or put it where it belongs in main:
1
2
3
4
5
6
    int main()
{
    ...

    //WHILE LOOP HERE
}


As a general rule you can't have statements such as loops outside of functions in a .cpp file. Okay you can have global variables and constants but those are generally not advised.

Hope that makes things clearer for you
Last edited on
Ok...

So can you move the whole
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
while(p1.numberOfPiecesAlive =>0 && p2.numberOfPiecesAlive =>0) //Replace and by &&
	{
	     //player one just chose x and y
	if (player2.pieceBoard[chosenY][chosenX] == 'P')
		{
			cout << "\nHit a boat!":
			player1.otherBoard[chosenY][chosenX} = 'X';
			player2.pieceBoard[chosenY][chosenX] == 'X'
			player2.numberOfPiecesAlive -= 1;
		}
	else
		{
			cout << "\nYou missed all the boats.."
			player1.otherBoard[chosenY][chosenX} = 'M'; //M for miss, or anything you like
		}
		
	return;
}


to

1
2
3
4
5
6
7
8
9
    int main(){}
//While Loop Here
    void initBoard(char board[][GRID_SIZE]){}
    void displayBoard(char board[][GRID_SIZE]){}
    void placePieces(std::string name, char board[][GRID_SIZE]){}
    void saveGame(player_t p1, player_t p2){}
    void loadGame(player_t *p1, player_t *p2){}
//Or here
 
1
2
3
4
5
6
7
8
    int main(){}
//While Loop Here
    void initBoard(char board[][GRID_SIZE]){}
    void displayBoard(char board[][GRID_SIZE]){}
    void placePieces(std::string name, char board[][GRID_SIZE]){}
    void saveGame(player_t p1, player_t p2){}
    void loadGame(player_t *p1, player_t *p2){}
//Or here 

If you're doing it like so, you have to include the loop inside a function as I mentioned above. And then you have to call the function in main()


However, seeing how many arguments you're have to pass to the function I highly suggest that you directly use it in your main function!
Last edited on
Topic archived. No new replies allowed.