Hi all, italian newbie here.
My english is not enough to explain in words my problem, and my program is 400 lines long by now... I think I'll post only the parts of code that I think are useful...
I typedefined some struct, and the last gives some problem to me.
Code:
typedef enum colore{blu, rosso}
Team;
/*il colore determina di quale giocatore sia il carroarmato*/
typedef struct{
int numero;
Team colore;
} Tanks;
/*questa struct rappresenta i carro armati di una casella,
hanno un colore e una quantità*/
typedef struct territory{
Tanks carriArmati;
struct territory* sopra; //puntatore al territorio sopra
struct territory* destra; //puntatore al territorio a destra
struct territory* sotto; //puntatore al territorio sotto
struct territory* sinistra; //puntatore al territorio a sinistra
} Territory;
The problem is to acced to the member numero of carriArmati of Territory... here's what I've done:
Code:
int main(int argc, char** argv)
..
Territory** campo; //variabile che punta all'inizio del campo di gioco
..
campo = (Territory**)malloc(sizeof(Territory)*N);
for(i=0;i<N;i++){
campo[i] = (Territory*)malloc(sizeof(Territory)*M);
}
and that's how I declared the Territory** campo and allocated the space for it, and I'm not sure this is important, but that's how I filled it
Code:
for(i=0;i<N;i++){ //inizializzazione del campo
for(j=0;j<M;j++){
if(i==0) campo[i][j].sinistra = &campo[N-1][j]; //se ci troviamo nella prima colonna della matrice, il territorio adiacente a sinistra è quello nell'ultima colonna e stessa riga
else campo[i][j].sinistra = &campo[i-1][j];
if(i==N-1) campo[i][j].destra = &campo[0][j]; //se ci troviamo nell'ultima colonna...
else campo[i][j].destra = &campo[i+1][j];
if(j==0) campo[i][j].sopra = &campo[i][M-1]; //se ci troviamo nella prima riga...
else campo[i][j].sopra = &campo[i][j-1];
if(j==M-1) campo[i][j].sotto = &campo[i][0]; //se ci troviamo nell'ultima riga...
else campo[i][j].sotto = &campo[i][j+1];
campo[i][j].carriArmati.numero = 0;
}
}
then I call a function like this:
Code:
stampaCampo(campo);
and there, finally, there's the instruction that gives me problems:
Code:
if(campo[i-1][j-1].carriArmati.numero == 0)
the whole program compile, but then it gives me:
"Thread 1: program received signal: EXC_BAD_SIGNAL"