I'm trying to make a dynamic matrix that is based on an integer pointer to pointer, this variable is allocated dynamically, but I'm having a little trouble using it, I don't know if I am using it wrong or something, but the outcome is not as expected. Is it something wrong that I'm doing or am I not thinking this through?
void pkn(int n, int k)
{
int chec = checagemInicial(n,k);
if(chec == 1)
{
return;
}
int mat[n];
int **resultado = NULL, **newMem;
int posicoes = 0;
initiateArray(mat, n);//initialize the matrix with one's
while(functionthatchecksthings1(mat, n, k) == 0)//this 2 function works no need to worry
{
if(functionthatchecksthings2(mat, n , k))
{//i think the problem might be or here
newMem = realloc(resultado, ((sizeof(int)*n)+(posicoes*sizeof(int)*n)));
if(newMem)
{//or here
resultado = newMem;
}
int i = 0;
for(i; i<n;i++)
{//or here but don't know where
resultado[posicoes][i] = mat[i];
}
posicoes++;
}
somaArray(mat, k, n-1);
}
//or in the very least case i'm printing it wrong
printaArray(resultado, n, posicoes);
system("pause");
free_matrix(posicoes, resultado);
}
This one is the function that prints the pointer, it might be wrong here too, but I seriously don't know.
void printaArray(int **ar, int n, int p)
{
int i = 0, j;
for(i; i < p; i++)
{
j = 0;
for(j; j < n; j++)
{
printf("%d ",(ar[i][j]));
}
printf("\n");
}
printf("%d\n", p);
}
I would like to thank everyone and I'm sorry if I haven't made myself clear, or if I've said something wrong/misspelled anything