I am trying to dynamically allocate a 2D array using calloc.
Here is the code that I have tried.
int ** numberOfConstPiArray = calloc(invariannumberOfUniqueKernels * kernelColumnCount, sizeof(int *));
I have initialised the following variables as shown
int numberOfUniqueKernels = 100;
int kernelColumnCount = 10;
int dimensionalMatrixColumnCount = 10;
The following is the main code which loops through and tries to alter the 2D array.
for (int countKernel = 0; countKernel < numberOfUniqueKernels; countKernel++)
{
int countNumberOfConst = 0;
int numberOfTerms = 0;
int numberOfConstPi = 0;
for (int col = 0; col < kernelColumnCount; col++)
{
for (int row = 0; row < dimensionalMatrixColumnCount; row++)
{
if (some condition is satisfied)
{
countNumberOfConst += 1;
}
if (another condition satisfied)
{
numberOfTerms += 1;
}
}
if(countNumberOfConst == numberOfTerms)
{
numberOfConstPi += 1;
numberOfConstPiArray[countKernel][col] = 1;
}
countNumberOfConst=0;
numberOfTerms=0;
}
}
This doesn't seem to work. I understand that doesn't seem to work is vague but as this code is a part of a large compiler, there is no way for me to print out the specific output. Apologies for that.
My question is: Have I initialised the arrays in the correct way and have is the way I modified the values of the elements in the array correct.
Thank you.