0
Well, it’s compiling everything ok, however, when I print out the elements of the entire tab matrix[8][8], which is a member of the checksum structure, the compiler, in a way is assigning numbers to this matrix, which I don’t know where they came from, since the matrix should contain 1, -1 or 0. However, it stores relatively large values, which I suspect are memory positions. I managed to get around this obstacle by passing the address of the main structure to the functions (obviously, the parameters of the functions have also been modified to allow this). Then, in the functions, I used the operator of (->) instead of (.) since I was working with the pointer of a structure. The fruits from this, were the goals that I longed for. However, I did 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");
}
And what should happen? It’s running like this: http://ideone.com/CHrz3X
– Maniero