Question: This is for C Programming: I have the following errors and really need help fixing them. Thank you. MAKE FILE: all: battleship.x battleship.x: game.o battleship.o
This is for C Programming: I have the following errors and really need help fixing them. Thank you.

MAKE FILE:
all: battleship.x
battleship.x: game.o battleship.o
gcc -std=c99 -Wall game.o battleship.o -o battleship.x
game.o: game.c battleship.c battleship.h
gcc -std=c99 game.c -c
battleship.o: battleship.c battleship.h
gcc -std=c99 battleship.c -c
clean:
rm *.o *.x
BATTLESHIP.C
#include
#include
#include
#include
#include "battleship.h"
/* This function prints out the following: welcomes the player and provides some background
information about the game of Battleship.*/
void welcomeBattleship(void)
{
printf("--------------------WELCOME TO BATTLESHIP---------------------- ") ;
printf("--Battleship is a classic Milton-Bradley game,where two ------- ");
printf("--players, in secret, position their navy on a grid.----------- ");
printf("--Each ship in the navy covers a contiguous horizontal--------- ");
printf("--or vertical section of grid cells.--------------------------- ");
printf("--The type of ship determines the number of grid cells covered. ");
printf("--The players, in turn, lob salvos at each others navy by----- ");
printf("--calling out grid locations. --------------------------------- ");
printf("--Should a salvo coincide with a grid cell covered by a ship-- ");
printf("--location, the attacked player calls out hit.--------------- ");
printf("--If the salvo does not coincide with a cell covered----------- ");
printf("--by a ship, the attacked player calls out miss.------------- ");
printf("--If all the cells covered by a single ship are hit,----------- ");
printf("--the attacked player calls out sunk.------------------------ ");
printf("--The first player to sink all of the opponents ship wins.---- ");
printf(" ");
}
// This function prints out the rules of the game
void printGameRules(void)
{
printf("RULES OF THE GAME: ");
printf("1. This is a two player game. ");
printf("2. Player 1 is you, and player 2 is the computer. ");
printf("3. Player 1 will be prompted & input ships are placed ");
printf(" randomly. ");
printf("4. There are 5 types of ships: [c] carrier, [b] battleship ");
printf(" [d]destroyer, [s]submarine, and [p]patrol boat. ");
printf("5. The computer radomly selects which player goes first. ");
printf("6. The game begins as each player tries to guess the location ");
printf(" of the ships of the opposing game board. ");
printf("7. First player to guess the location aof all the ships wins. ");
}
//This decides and returns which which player goes first
int whoStartsFirst(void)
{
int player = 0,
select = 0;
select = rand() % 2;
if(select == 0)
{
printf("You go first. You are 'Player A'. ");
player = 1;
}
else
{
printf("I go first. I am 'Player B'. ");
player = 2;
}
return player;
}
void initializeBoard(int **playerBoard, int **compBoard)
{
const int rows = 10,
cols = 10;
for (int i = 0; i
{
playerBoard[i] = (int *)malloc(sizeof(int)*cols);
compBoard[i] = (int *)malloc(sizeof(int)*cols);
for (int j = 0; j
{
playerBoard[i][j] = '-';
compBoard[i][j] = '-';
}
}
}
void printBoard()
{
const int rows = 10,
cols = 10;
int **playerBoard = (int **)malloc(sizeof(int *)*rows);
int **compBoard = (int **)malloc(sizeof(int *)*rows);
initializeBoard(playerBoard, compBoard);
{
printf("SHIPS ");
printf("PLAYER 'A' ");
printf(" | ");
for (char c = 'A'; c
{
printf("%c ", c);
printf("| ");
}
printf(" ");
for (int i = 0; i
{
printf("%2d ", i + 1);
printf("|");
for (int j = 0; j
{
printf(" %c ", playerBoard[i][j]);
if (i == 10)
puts(""); //only triggers if i=10, 10x10grid
printf("|");
}
printf(" ");
}
}
puts(" ");
printf("PLAYER 'B' ");
printf(" | ");
for (char c = 'A'; c
{
printf("%c ", c);
printf("| ");
}
printf(" ");
for (int i = 0; i
{
printf("%2d ", i + 1);
printf("|");
for (int j = 0; j
{
printf(" %c ", compBoard[i][j]) + "|";
if (i == 10)
puts("");
printf("|");
}
printf(" ");
}
}
BATTLESHIP.H
#ifndef BATTLESHIP_H #define BATTLESHIP_H
void battleship(void); void welcomeBattleship(void); void printGameRules(void); void PressEnterToContinue(void); int whoStartsFirst(void); void initializeBoard(int ***board); void printBoard(int **board); void randomPlaceShips(int **board, int count, int symbol); void placeShips(int **board); void giveShot(int shot[2]); int hitShip(int shot[2], int symbol[][2]); void tip(int shot[2], int symbol[][2], int attempt); void changeBoard(int shot[2], int symbol[][2], int board[][2]);
#endif
GAME.C
#include
#include
#include
#include
#include "battleship.h"
int main(void)
{
// number of rows and cols
const int rows = 10,
cols = 10;
battleship();
welcomeBattleship();
PressEnterToContinue();
printGameRules ();
PressEnterToContinue();
// declare boards
int **playerBoard, **compBoard;
// initialize them
initializeBoard(&playerBoard);
initializeBoard(&compBoard);
int symbol[100][2];
int board[100][2];
int player = 0;
srand(time(NULL));//required for "randomness"
player = whoStartsFirst();
PressEnterToContinue();
printf("SALVOS ");
printf("PLAYER 'A' ");
printBoard(playerBoard);
printf("PLAYER 'B' ");
printBoard(compBoard);
placeShips(playerBoard);
placeShips(compBoard);
printf("SHIPS ");
printf("PLAYER 'A': ");
printBoard(playerBoard);
//printf("PLAYER 'B': ");
//printBoard(compBoard);
int shot[2];
int attempts=0,
hits = 0;
do
{
printf("SALVOS ");
printf("PLAYER 'A' ");
printBoard(playerBoard);
giveShot(shot);
attempts++;
if(hitShip(shot, symbol))
{
tip(shot, symbol, attempts);
hits++;
}
else
{
tip(shot, symbol, attempts);
changeBoard(shot, symbol, board);
}
}
while(hits!=5);
printf(" You hit the ships in %d attempts", attempts);
printf("SALVOS ");
printf("PLAYER 'A' ");
printBoard(playerBoard);
printf("PLAYER 'B' ");
printBoard(compBoard);
return 0;
}
gcc -std-c99 game.c c cc -std-c99 battleship.c battleship.c:81:6: conflicting types for 'initializeBoard er void initializeBoard (int **playerBoard, int **compBoard) In file included from battleship.c:13:0 battleship.h:16:6: note: previous declaration of 'initializeBoard' was here void initializeBoard(int ***board) battleship.c: In function printBoard': battleship.c:101:1 : error: number of arguments doesn't match prototype In file included from battleship.c:13:0 battleship.h:17:6 void printBoard(int **board) prototype declaration battleship.c: In function main' battleship.c:179:2: error too few arguments to function 'printBoard printBoard); battleship.c:100:6: note: declared here void printBoard() makefile:10: recipe for target 'battleship.o' failed make: ***[battleship.o] Error 1 gcc -std-c99 game.c c cc -std-c99 battleship.c battleship.c:81:6: conflicting types for 'initializeBoard er void initializeBoard (int **playerBoard, int **compBoard) In file included from battleship.c:13:0 battleship.h:16:6: note: previous declaration of 'initializeBoard' was here void initializeBoard(int ***board) battleship.c: In function printBoard': battleship.c:101:1 : error: number of arguments doesn't match prototype In file included from battleship.c:13:0 battleship.h:17:6 void printBoard(int **board) prototype declaration battleship.c: In function main' battleship.c:179:2: error too few arguments to function 'printBoard printBoard); battleship.c:100:6: note: declared here void printBoard() makefile:10: recipe for target 'battleship.o' failed make: ***[battleship.o] Error 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
