Well, it's compiling everything ok, however, when I'm going to print the elements of the entire array tab [8] [8], which is a member of the lady structure, the compiler is somehow assigning numbers to this array, the which I do not know where they came from, since the array should contain 1, -1 or 0. However, it stores relatively large values, which I suspect are memory locations. I managed to circumvent this constraint by passing the address of the lady structure to the functions (obviously, the parameters of the functions have also been modified, so as to allow this). So, in the functions, I used the (-> gt;) operator instead of (.), Since I was working with the pointer of a structure. The fruits from this were the goals I wanted. However, I do not understand why the code below does not work as it should.
#include<stdio.h>
#define SIZE 8
typedef struct jogo {
int tab[SIZE][SIZE];
/*p[0] == constante que denota
o player enquanto p[1] == qt de
pecas que o jogador possui*/
int player_1[2];
int player_2[2];
} tabuleiro;
void inicializar (tabuleiro p);
void mostrar (tabuleiro p);
int main() {
register int i, j;
tabuleiro dama;
inicializar(dama);
mostrar(dama);
return 0;
}
/*Inicializa o tabuleiro de dama*/
void inicializar (tabuleiro p) {
register int i, j;
p.player_1[0] = -1;
p.player_2[0] = 1;
p.player_1[1] = p.player_2[1] = SIZE;
for (i = 0; i < SIZE; ++i) {
for (j = 0; j < SIZE; ++j) {
if ((i == 0 && j % 2 == 1)
|| (i == 1 && j % 2 == 0))
p.tab[i][j] = p.player_1[0];
else if ((i == 6 && j % 2 == 1)
|| (i == 7 && j % 2 == 0))
p.tab[i][j] = p.player_2[0];
else p.tab[i][j] = 0;
}
}
}
/*Apresenta o tabuleiro de dama*/
void mostrar (tabuleiro p) {
register int i, j;
printf("\n\n|---|---|---|---|---|---|---|---|\n");
for (i = 0; i < SIZE; ++i) {
for (j = 0; j < SIZE; ++j) {
if (p.tab[i][j] == p.player_1[0])
printf("| X ");
else if (p.tab[i][j] == p.player_2[0])
printf("| O ");
else
printf("| ");
}
printf("|\n|---|---|---|---|---|---|---|---|\n");
}
printf("\n\n");
}