0
I’m having an error when I ask on the command line the values of WORLD X and WORLD Y
error: variable-sized Object may not be initialized AGENT *grid[WORLD_X][WORLD_Y] = { NULL };
/* Verificar se numero de argumentos foi o correto */
if (argc != 8) {
fprintf(stderr, "Modo de uso:\n");
fprintf(stderr, "\t%s -x -y -z -h -Z -H -t \n", argv[0]);
exit(-1);
}
unsigned int WORLD_X = atoi(argv[1]);
unsigned int WORLD_Y = atoi(argv[2]);
int NHUMANS = atoi(argv[3]);
int NZOMBIES = atoi(argv[4]);
int NHUMANS_PLAY = atoi(argv[5]);
int NZOMBIES_PLAY = atoi(argv[6]);
int TURNS = atoi(argv[7]);
/* An instance of a SHOWWORLD world display. */
SHOWWORLD *sw = NULL;
/* A by-dimensional array of agent pointers, representing agents in a
grid. In the final project the agent grid or world should be abstracted
to specific world.c/world.h files, with new/destroy functions
All elements in this grid are initialized to NULL, i.e., they don't
initially point to anything. */
AGENT *grid[WORLD_X][WORLD_Y] = { NULL };
Program compilation is using the following command -Wall -Wextra -Wpedantic -Std=C99 -g in the ubuntu
You could instantiate in the hand at the worst of times. Or with
memset
, I think ofstring.h
. Tell which is the compiler maybe have relevance, maybe one or the other behave in a differentiated way for the initialization of values– Jefferson Quesado
Need to allocate memory in creating two-dimensional array
– Claudio Lopes