hey, i'm trying to write a function that checks whether an array element (chosen by the user's input) is empty (aka NULL) or full (aka has a value in it). there is lots of code missing in this, because it's actually going in another program, but yeah, rewrite it like this to test out the function, and I can't seem to get it to work. The problem is what ever value I enter when prompted, returns "%d is full", where %d is my value. the code is pretty confusing, well atleast to me, but hopefully you can understand it and what i'm trying to do. Thanks!
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char cBoard[3][3];
int x;
int y;
int z = 0;
int iSquare;
printf("Enter a square number <1-9>: ");
scanf("%d", &iSquare);
memset(&cBoard,0,sizeof(cBoard));
for (x=1; x <= 3; x++)
{
for (y=1; y <= 3; y++)
{
z++;
if (iSquare == z)
{
if (&cBoard[x-1][y-1] == NULL)
{
printf("\n\n%d is Empty!\n\n", iSquare);
}
else
{
printf("\n\n%d IS FULL!\n\n", iSquare);
}
}
}
}
return 0;
}
p.s this is for a tick tack toe i'm trying to create. so yeah, the user input is selecting which square to put his mark in, 1-9, and this function will check whether the square is being used or not (if i can get it to work properly that is) when i pass it later in main() or something.