ボードゲームのグリッドを作成しようとしています。ボードの最大サイズはわかっていますが、ユーザーがコマンドラインに入力した内容に基づいて小さくすることもできます。次のプログラムを作成しました。コンパイルは成功しますが、寸法をコマンド ラインに書き込むと、「セグメンテーション違反 (コア ダンプ)」と表示されます。誰が私が間違ったことを教えてもらえますか?
#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]);
}