I'm having trouble modifying the content in a given position of a multidimensional array that is inside a structure. I have two structures struct TabelaFilial
and struct ArrTabela
. The struct TabelaFilial
structure is being pointed out by an incomplete type typedef struct TabelaFilial *TabelaFiliais
and the structure struct ArrTabela
by typedef struct ArrTabela *ArrTabelaFiliais
. The TabelaFilial
structure has a matrix with 14 lines: char *(*m)[14]
and the ArrTabela
structure has an array with 3 positions in which each position points to the TabelaFilial
structure. Here are the structures:
struct TabelaFilial
{
char *(*m)[14];
};
typedef struct TabelaFilial *TabelaFiliais;
struct ArrTabela
{
TabelaFiliais tab[3];
};
typedef struct ArrTabela *ArrTabelaFiliais;
Initialize the structures thus:
void iniciaTabela (TabelaFiliais t)
{
t = (TabelaFiliais ) malloc (sizeof (struct TabelaFilial));
t->m = malloc (sizeof (char*) * 9);
int l , c;
for (l = 0 ; l < 14 ; ++l)
for (c = 0 ; c < 9 ; ++c)
t->m[l][c] = NULL;
}
void iniciaArr (ArrTabelaFiliais arr)
{
int i;
arr = (ArrTabelaFiliais)malloc(sizeof (struct ArrTabela));
for (i = 0 ; i < 3 ; ++i)
iniciaTabela(arr->tab[i]);
}
I would like to access the array tab[3]
in position 0 of the structure ArrTabela
and change its content.
I used this small function:
void TabelaFilial (ArrTabelaFiliais arr)
{
int l , c;
for (l = 0 ; l < 14 ; ++l)
for (c = 0 ; c < 9 ; ++c)
strcpy ((arr->tab[0]->m[l][c]) , "||||||");
}
However, I got a Segmentation fault (core dumped)
.
What am I doing wrong? And how can I fix it?