Hello I'm confused how to build a 9x9 board using 2d arrays. I attached what my board should look like. I looked at the information online for help but i couldn't really understand. I want to build the board and understand how to print and edit the arrays. If you could help me understand that would be great. this is what i have so far.
Code:
#include <stdio.h>
# define length 9
# define width 9
int main (void){
int row;
int col;
int i=0;
int count=0;
int mines;
int randomseed;
printf("please input your seed: ");
scanf("%d", &randomseed);
printf("please input the number of mines: ");
scanf("%d", &mines);
//create the gameboard size
int gameboard[length][width];
//read in the gameboard file
//for each row
for(row=0; row<length; row++)
{
//for each col
for(col=0; col<width; col++)
{
scanf("%d", &i);
gameboard[row][col]=i;
}
}
//check in the readin file
//for each row
for(row=0; row<length; row++)
{
//for each col
for(col=0; col<width; col++)
{
//prints an X in place of every 1
if(gameboard[row][col]==1)
{
printf("X ");
}
//prints out the other numbers for how many mines are found by each space
else
{
//finds 0's and checks how many X's are around them
if(gameboard[row][col]==0)
{
count = 0;
if(gameboard[row][col+1]==1)
{
count=count+1;
}
if(gameboard[row][col-1]==1)
{
count=count+1;
}
if(gameboard[row+1][col]==1)
{
count=count+1;
}
if(gameboard[row-1][col]==1)
{
count=count+1;
}
if(gameboard[row+1][col+1]==1)
{
count=count+1;
}
if(gameboard[row+1][col-1]==1)
{
count=count+1;
}
if(gameboard[row-1][col+1]==1)
{
count=count+1;
}
if(gameboard[row-1][col-1]==1)
{
count=count+1;
}
printf("%d ", count);
}
}
}
printf("\n");
}
printf("\n");
return 0;
}