Basically i want the variable 'End' to control the while loop. In the while loop there is a function called to check multiple things (Is the game tic tac toe) when the function see a tris or the table full (tie) it should change the variable 'End' to -1 if someone wins or -2 if is a draw so the game should end. (This doesn't happen)
printf("TURN %u
", COUNT); //conta turno (inglese)
printf("Player %d:
", Start_Num); //giocata player1
printf("ROW: ");
scanf("%u", &ROW);
if (ROW > 2){
puts("ENTER A VALID VALUE (BETWEEN 0 AND 2)"); //decisione mossa
scanf("%u", &ROW);
}
printf("COLUMN: ");
scanf("%u", &COLUMN);
if (COLUMN > 2){
puts("ENTER A VALID VALUE (BETWEEN 0 AND 2)");
scanf("%u", &COLUMN);
}
if (Start_Num == 1){ //assegnazione mossa all'array
TABLE[ROW][COLUMN] = P1_SIGN;
}
else {
TABLE[ROW][COLUMN] = P2_SIGN;
}
Print_Table_Full(TABLE); //funzioni
Verify_Win_Or_Tie(TABLE, P1_SIGN, P2_SIGN, End, Counter_Obj);
COUNT++;
}
The while loop is incomplete but it should work anyway
if(TABLE[0][0] && TABLE[0][1] && TABLE[0][2] == P1_SIGN){ //prima riga
puts("PLAYER 1 WINS
");
End = -1; //valore di vincita
}
if(TABLE[0][0] && TABLE[0][1] && TABLE[0][2] == P2_SIGN){
puts("PLAYER 2 WINS
");
End = -1;
}
if(TABLE[1][0] && TABLE[1][1] && TABLE[1][2] == P1_SIGN){ //seconda riga
puts("PLAYER 1 WINS
");
End = -1;
}
if(TABLE[1][0] && TABLE[1][1] && TABLE[1][2] == P2_SIGN){
puts("PLAYER 2 WINS
");
End = -1;
}
if(TABLE[2][0] && TABLE[2][1] && TABLE[2][2] == P1_SIGN){ //terza riga
puts("PLAYER 1 WINS
");
End = -1;
}
if(TABLE[2][0] && TABLE[2][1] && TABLE[2][2] == P2_SIGN){
puts("PLAYER 2 WINS
");
End = -1;
}
if(TABLE[0][0] && TABLE[1][0] && TABLE[2][0] == P1_SIGN){ //prima colonna
puts("PLAYER 1 WINS
");
End = -1;
}
if(TABLE[0][0] && TABLE[1][0] && TABLE[2][0] == P2_SIGN){
puts("PLAYER 2 WINS
");
End = -1;
}
if(TABLE[0][1] && TABLE[1][1] && TABLE[2][1] == P1_SIGN){ //seconda colonna
puts("PLAYER 1 WINS
");
End = -1;
}
if(TABLE[0][1] && TABLE[1][1] && TABLE[2][1] == P2_SIGN){
puts("PLAYER 2 WINS
");
End = -1;
}
if(TABLE[0][2] && TABLE[1][2] && TABLE[2][2] == P1_SIGN){ //terza colonna
puts("PLAYER 1 WINS
");
End = -1;
}
if(TABLE[0][2] && TABLE[1][2] && TABLE[2][2] == P2_SIGN){
puts("PLAYER 2 WINS
");
End = -1;
}
if(TABLE[0][0] && TABLE[1][1] && TABLE[2][2] == P1_SIGN){ //diagonale 1
puts("PLAYER 1 WINS
");
End = -1;
}
if(TABLE[0][0] && TABLE[1][1] && TABLE[2][2] == P2_SIGN){
puts("PLAYER 2 WINS
");
End = -1;
}
if(TABLE[0][2] && TABLE[1][1] && TABLE[2][0] == P1_SIGN){ //diagonale 2
puts("PLAYER 1 WINS
");
End = -1;
}
if(TABLE[0][2] && TABLE[1][1] && TABLE[2][0] == P2_SIGN){
puts("PLAYER 2 WINS
");
End = -1;
}
for(size_t i = 0; i < 3; i++){
for(size_t j = 0; j < 3; j++){
if(TABLE[i][j] == 'X' || TABLE[i][j] == 'O'){
Counter_Obj++;
}
}
}
if (Counter_Obj == 9){
puts("DRAW!");
End = -2;
}
return End;
}
I even tried to use pointers. The variable End was
int End = 0;