I'm trying to make a grid for a board game, i know the maximum size the board can be however it can also be smaller based on what the user inputs in the command line. I have made the following program, it compiles successfully but when i write the dimensions into the command line it says 'Segmentation fault (core dumped)'. Can anyone tell me what i've done wrong?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BOARD_WIDTH 80
#define BOARD_HEIGHT 52
int i;
int j;
int width;
int height;
int generations;
int grid[BOARD_WIDTH][BOARD_HEIGHT];
int main(int argc, char *argv[])
{
if (argc < 2)
{
printf("Not enough arguments entered\n");
exit(1);
}
else
{
width = atoi(argv[2]);
height = atoi(argv[3]);
generations = atoi(argv[4]);
}
for(i=0;i<width;i++)
for(j=0;j<height;j++)
printf("%2d", grid[i][j]);
}