1. ## Building TickTackToe

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..

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("&#37;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..");
}
Here is what happens:

Code:
[mag1x@localhost ~]\$ ./wtf
Enter a square number <1-9>: 1
EMPTY
Valid Choice, square was empty!
[mag1x@localhost ~]\$
It says empty for 1, 2 and 3, but if I enter 4 - 9 it says:

Code:
Enter a square number <1-9>: 6
I failed..Square being used or invalid number.
[mag1x@localhost ~]\$

2. It's because you have another "scanf" in the CheckSquare function. You need to enter another number before it will continue.

3. Oh hehe silly mistake, was changing around the functions etc, must have missed that one :P But now there is another problem. When enter the number, it say it's being used, even if it isn't.

4. Can you rewrite your CheckSquare?

5. Originally Posted by manav
Sure, all fixed, added a more detailed description of the new problem too.

6. Code:
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;
}
}
}
The use of "for" in here only counts up to 3 times. If the number entered
exceeds three, it no longer goes through the "EMPTY/FULL check";

A possible solution is to omit the x&y variables and make an array of 9 intergers.