I have this structure containing links to the same structure type (peca). The problem is that when I try and use peca->penext in a different function, the debugger shows that the structure peca is not linked to the next or previous. What am I doing wrong?
typedef struct peca{
int index;
int esquerda;
int direita;
int disponibilidade;
struct peca *penext;
struct peca *peant;
}PECA;
typedef struct mao{
int index;
int tamanho;
PECA *ppeca;
struct mao *pnext;
}MAO;
typedef struct jogada{
int index;
PECA *ppeca;
struct jogada *pnext;
}JOGADA;
typedef struct jogo{
int nr_maos;
MAO *pmao;
JOGADA *pjog;
}JOGO;
void init_jogada(JOGADA *pj) {
pj->ppeca = (PECA *) malloc(sizeof(PECA) * 28);
PECA *paux = pj->ppeca;
for (int i = 0; i < 28; ++i) {
paux->index = i;
paux->disponibilidade = 1;
if (i == 0)
{
paux->peant = NULL;
paux->penext = paux++;
}
else if (i == 27)
{
paux->peant = paux--;
paux->penext = NULL;
}
else
{
paux->penext = paux++;
paux->peant = paux--;
}
paux++;
}
}