Question: This is for C programming: I am slowly creating functions for my battleshp program. I am trying to create the following function to randomly place
This is for C programming: I am slowly creating functions for my battleshp program. I am trying to create the following function to randomly place the folliwng ships on my grid. I would greatly appreciate help creating the function for this placement. Thank you so much.

I have included the code I have worked on so far. I am still having a few issues with my grid, but for the most part I have the folloiwng output for my grid:

MY CODE:
MAIN:
int main(void)
{
welcomeBattleship();
printGameRules ();
int player = 0;
srand(time(NULL));//required for "randomness"
player = whoStartsFirst();
printBoard();
return 0;
}
THIS IS MY FUNCTION FOR INITIALIZING AN PRINTING MY BOARD. (STILL HAVING ISSUES WITH IT)
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("\t| ");
for (char c = 'A'; c
{
printf("%c ", c);
printf("| ");
}
printf(" ");
for (int i = 0; i
{
printf("%d ", 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(" ");//only triggers if 1 =10, 10x10 grid
printf(" |");
for (char c = 'A'; c
{
printf("%c ", c);
printf(" |");
}
printf(" ");
for (int i = 0; i
{
printf("%d ", i + 1);
printf("|");
for (int j = 0; j
{
printf("%c ", compBoard[i][j]) + "|";
if (i == 10)
puts("");
printf("|");
}
printf(" ");
}
}
Designator Ship type Number of cells Carrier Battleship Destroyer Submarine Patrol Boat
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
