I am passing the address of the variable 'jog' to the function 'aplica_cordenada', and I update its values inside that function's definition, but it is not being updated outside of it. I am aware of variable scope, but since I'm passing its address (&jog), shouldn't it be updated outside the function as well?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define TRUE 1
#define FALSE 0
/* === PROTÓTIPOS DAS FUNÇÕES. === {{{ */
int run_game(int);
void aplica_cordenada(char [], int *);
/* === Protótipos fim. }}} */
int main(void) { /* {{{ */
/* === VARIABLES === {{{ */
/* Jogador 1 ou 2. */
int jog = 1;
//int *ptr_jog;
//ptr_jog = &jog;
/* Mantém o jogo rodando. */
int run = 1;
int i = 0, j = 0; /* Iteradores. */
char casas[10] = {'-', '-', '-', '-', '-', '-', '-', '-', '-'};
int cord = 0;
/* End variables. }}} */
do { /* {{{ */
printf("jog %d\n", jog);
if (jog % 2 != 0) { // {{{
printf("Jogador um...\n\n");
}
else {
printf("Jogador dois.\n\n");
} // }}}
for (i = 0; i < 10; i++) { // {{{
printf(" %c ", casas[i]);
if (i == 2 || i == 5) {
printf("\n"); /* Formatar colunas. */
}
}
printf("\n\n"); // }}}
aplica_cordenada(casas, &jog);
} while (run_game(run)); /* Fim de do while. }}} */
return 0;
} /* main() fim. }}} */
/* === DEFINIÇÕES DAS FUNCÕES. {{{ */
int run_game(int T) { // {{{
return TRUE;
} // }}}
void aplica_cordenada(char casas[], int *ptr_jog) { /* {{{ */
char opt;
do {
printf("Digite uma posição: ");
opt = getchar();
} while (!isdigit(opt) || opt == '0');
opt = atoi(&opt); /* Converter para número. */
printf("casa %d -- \n", opt);
if (casas[opt - 1] == '-') {
casas[opt - 1] = 'x';
*ptr_jog++;
}
} /* Funções cordenada() fim. }}} */
int casa_disponivel(int n) { /* {{{ */
return FALSE;
} /* }}} */
/* Definiçoes fim }}} */
/*
* vim:foldmethod=marker foldmarker={{{,}}}
*/
Thanks in advance.