Syntax error C [closed]

0

I read the chapter of matrices in Herbert Schildt's book, C complete and total, and I decided to transcribe the algorithm elaborated to simulate an old game. After all, Dev-c ++ encountered a syntactic error. Would anyone know to answer me why?

/* Um exemplo de jogo-da-velha simples */
#include <stdio.h>
#include <stdlib.h>

char matrix[3][3]; /* A matriz do jogo */

char check(void);
void int_matrix(void);
void get_player_move(void);
void get_computer_move(void);
void disp_matrix(void);

void main(void)
{
char done;

printf("Este é o jogo-da-velha\n");
printf("Você estará jogando contra o computador\n");

done = ' ';
init_matrix();
do{
    disp_matrix();
    get_player_move();
    done = check(); /* Verifica se há vencedor */
    if(done!=' ') break; /* Vencedor */
    get_computer_move();
    done = check(); /* Verifica se há vencedor */
} while(done == ' ');
if(done == 'X') printf("Voce ganhou!\n");
else printf("Eu ganhei!\n");
disp_matrix(); /* Mostra as posições finais */
}

/* Inicializa a matriz */

void init_matrix(void)
{
int i, j;

for(i=0; i<3; i++)
    for(j=0; j<3; j++) matrix[i][j] = ' ';
}

/* Obtém a sua jogada */

void get_player_move(void)
{
int x, y;

printf("Digite as coordenadas para o X: ");
scanf("%d%d", &x, &y);

x--; y--;

if(matrix[x][y] != ' '){
    printf("Posicao invalida, tente novamente\n");
    get_player_move();
}
else matrix[x][y] = 'X';
}

/* Obtém uma jogada do computador */

void get_computer_move(void)
{
int i, j;
for(i=0; i<3; i++){
    for(j=0; j<3; j++)
        if(matrix[i][j] == ' ') break;
    if(matrix[i][j] == ' ') break;
}
if(i*j == 9){
    printf("Empate\n");
    exit(0);
}
else
    matrix[i][j] = 'O';
}

/* Mostra a matriz na tela */

void disp_matrix(void)
{
int t;

for(t=0; t<3; t++){
    printf(" %c | %c | %c ", matrix[t][0], matrix [t][1], matrix[t][2]);
    if(t != 2) printf("\n---|---|---\n");
}
printf("\n");
}

/* Verifica se há um vencedor */

char check(void)
{
int i;

for(i=0; i<3; i++) /* Verifica as linhas */
    if(matrix[i][0] == matrix[i][1] && matrix[i][0] == matriz[i][2]) return matrix[i][0];

for(i=0; i<3; i++) /* Verifica as colunas */
    if(matrix[0][i] == matrix[1][i] && matrix[0][i] == matrix[2][i]) return matrix[0][i];

/* Testa as diagonais */

if(matrix[0][0] == matrix[1][1] && matrix[1][1] == matriz[2][2]) return matrix[0][0];
if(matrix[0][2] == matrix[1][1] && matrix[1][1] == matriz[2][0]) return matrix[0][2];

return ' ';
}

Error occurs at line 101, as you can see above in the image.

    
asked by anonymous 14.10.2016 / 03:18

1 answer

3

Your array was declared matrix ; but not only in the 101 line but also in the 108 and 109 we see calling array , so the error

if(matrix[i][0] == matrix[i][1] && matrix[i][0] == **matriz**[i][2]) return matrix[i][0]; 

replace with:

if(matrix[i][0] == matrix[i][1] && matrix[i][0] == **matrix**[i][2]) return matrix[i][0];
Ready! now it should work!

Att.

    
14.10.2016 / 03:28