我正在尝试制作一个基于指向指针的整数指针的动态矩阵,这个变量是动态分配的,但我使用它时有点麻烦,我不知道我是否使用它错了或某事,但结果不如预期。我正在做的事情是错的还是我没有想到这一点?
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);
}
我要感谢大家,如果我没有说清楚,或者我说错了什么/拼错了什么,我很抱歉