Hey, this is for a tick tack toe game I'm creating, basically so far what i'm trying to get it to do is check if the array is empty, so later i can fill the array with the persons symbol (x) or (O). But yeah, it asks for the users input, i enter a number, and I get mixed results, depending on the number I enter, even if the arrays are ALL empty..
Here is what happens:Code:#include <stdio.h> #include <string.h> #include <stdlib.h> int *iPointer1; int *iPointer2; int x; int y; char cBoard[3][3] = {0}; int CheckSquare(int); int main() { int iSquare; iPointer1 = &x; iPointer2 = &y; printf("Enter a square number <1-9>: "); scanf("%d", &iSquare); if (CheckSquare(iSquare) == 0) { printf("\nValid Choice, square was empty!\n"); } else { printf("Square being used or invalid number.\n"); } return 0; } int CheckSquare(int iSquare) { int z = 0; for (*iPointer1=1; *iPointer1 <= 3; (*iPointer1)++); { for (*iPointer2=1; *iPointer2 <= 3; (*iPointer2)++) { z++; if (z == iSquare) { if (cBoard[(*iPointer1)-1][(*iPointer2)-1] == 0) { printf("EMPTY"); return 0; } else { printf("\nFULL\n"); return 1; } } } } printf("I failed.."); }
It says empty for 1, 2 and 3, but if I enter 4 - 9 it says:Code:[mag1x@localhost ~]$ ./wtf Enter a square number <1-9>: 1 EMPTY Valid Choice, square was empty! [mag1x@localhost ~]$
Code:Enter a square number <1-9>: 6 I failed..Square being used or invalid number. [mag1x@localhost ~]$



LinkBack URL
About LinkBacks



