I'm trying to run through a 2-dimensional array and update values using a pointer to pointer to int.
Swap function:
void foo(int ** vacancies, int **transfers, int transfer)
{
for (int i = 0; i < transfer; i++)
{
(*transfers[i]) = 0;
(*vacancies[i]) = 2;
}
}
Declaration:
int ** vacancies = new int*[getVacancies(grid)];
int ** transfers = new int*[transfer];
Function call:
foo(vacancies, transfers, transfer);
Unfortunately this doesn't seem to actually update any values, is there something I need to change? Thanks!
Edit:
getVacancies(vacancies, grid, transfer);
getTransfers(transfers, grid, transfer);
void getVacancies(int ** vacancies, int grid[][ROW], int vCount)
{
for (int i = 0; i < vCount; i++)
{
for (int row = 0; row < ROW; row++)
{
for (int col = 0; col < COL; col++)
{
if (grid[col][row] == 0)
{
vacancies[i] = &grid[col][row];
}
}
}
}
}
And the same for getTransfers.
Edit 2:
void getVacancies(int ** vacancies, int grid[][ROW], int vCount)
{
int i = 0;
for (int row = 0; row < ROW; row++)
{
for (int col = 0; col < COL; col++)
{
if (grid[col][row] == 0)
{
vacancies[i] = &grid[col][row];
i++;
}
}
}
}