this is becoming NULL after for()

Greetings and Salutations! I have multiple questions. 1st:
[
Hex* canMoveTo[20];
for (int i = 0; i < sizeof(canMoveTo); i++)
{
canMoveTo[i] = nullptr;
}
Hex* temp;
bool done = false;
int moves = 0;
int seekerX = currentHex->xCoor;
int seekerY = currentHex->yCoor;
int iter = 0;
while (moves <= actions) // 1
{
temp = grid->getHex(seekerX--, seekerY++);
if (temp->inBounds)
{
if (temp->terrain->cost < actions &&temp->terrain->cost + moves < actions)
{
canMoveTo[iter] = temp;
moves += temp->terrain->cost;
iter++;
}
else break;
}
else break;
}
]
int i has a value of 80 after leaving the for loop. I'm fairly sure it should kick out of the loop once it equals 20, which is odd. Why would it exceed the conditions? 2nd: when i equals 22 [this] gets lost/set to [NULL] YIKES! 3rd: at the bottom of this function (assuming I forgo the for()):
[
int k = 0;
int j = 0;
while (!done)
{
k = rand() %20 ;
j++;
if (j > 4)
{
k -= j;
}
if (canMoveTo[k] != nullptr)
{
done = true;
}
}
]
You'll have to forgive my retaliatory int j rand() is flustering... when one is comparing pointers is that the correct way to do it? NULL is equivocal of 0? More than likely to change canMoveTo to a vector but I want to understand why it's breaking. Thanks in advance!
int i has a value of 80 after leaving the for loop. I'm fairly sure it should kick out of the loop once it equals 20, which is odd.
i doesn't exist after leaving the for loop. sizeof gives you the number of bytes needed to store an object. It does not give you the number of elements in an array.



Good! Thank you.
Topic archived. No new replies allowed.