I have this code, which is simulating Conway's game(not really important what that is for this question), and I was just wondering how to pass my array, board, to my function neighbor. I keep getting a compiler error saying that I have an incomplete element type in the function declaration, even though I was told I needed to put the empty square brackets there to pass functions, and it doesn't work without the square brackets. If anyone could help here to pass the function, that would be very helpful. Here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct info
{
int red;
int blue;
};
struct info neighbor(char board[][], int, int);
int main(int argc, char* argv[])
{
if(argc != 3)
{
printf("usage: dimensions repititions\n");
return 1;
}
srand(time(NULL));
int games = 0;
int d = atoi(argv[0]);
int repititions = atoi(argv[1]);
//create board
char board [d][d];
for(int i = 0; i < d; i++)
{
for(int j = 0; j < d; j++)
{
int choice = rand() % 100;
if(choice < 44)
{
if(choice % 2 == 0)
{
board[i][j] = '#';
}
else
{
board[i][j] = '*';
}
}
else
{
board[i][j] = '.';
}
}
}
while(games < repititions)
{
for(int i = 0; i < d; i++)
{
for(int j = 0; j < d; j++)
{
neighbor(board, i, j);
}
}
}
}
struct info neighbor(char board, int i, int j)
{
char grid [3][3];
for(int u = 0; u < 3; u++)
{
for(int v = 0; v < 3; v++)
{
grid[u][v] = board[i][j];
i ++;
}
j++;
}
}
char board[][]in the declaration butchar boardin the definition.struct info neighbor(char board, int i, int j)=>struct info neighbor(char *board, int i, int j)orstruct info neighbor(char board[][], int i, int j)it doesn't matter much because array's decay to pointers when called in functions like this.