我正在尝试创建一个基于指向指针的整数指针的动态矩阵,该变量是动态分配的,但是我在使用它时遇到了一点麻烦,我不知道我是不是用错了还是什么,但结果并不如预期。我做错了什么还是我没有考虑清楚?
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);
}
这个是打印指针的函数,这里也可能有问题,但我真的不知道。
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);
}
我要感谢大家,如果我没有说清楚,或者我说错了什么/拼错了什么,我很抱歉