[英]Matrix of type int using uint8_t data prints wrong when passed to a function
Ok so I got the following pointer sh and the array of matrices shadows. 好的,所以我得到了以下指针sh和矩阵数组阴影。
uint8_t * sh;
int shadows[k][330][210];
I fill the shadows like this: 我像这样填充阴影:
int rows = 165;
int cols - 105;
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
shadows[reached][i][j] = sh[index];
index++;
}
}
Then I can print for example shadows[0] like this: 然后我可以像这样打印阴影[0]:
int i;
int j;
for (i=0; i<rows; i++){
for(j=0; j<cols; j++){
printf("%d ", shadows[0][i][j]);
}
printf("\n");
}
Everything ok so far. 到目前为止一切都还好。 The print of shadows[0] looks fine.
阴影[0]的打印看起来很好。 Then I pass this matrix to a function like this:
然后我将这个矩阵传递给这样的函数:
separateMatrixByColumn(1, cols-1, rows, cols, shadows[0], v[0], g[0]);
Inside of that functions the first thing I do is print the matrix shadows: 在函数内部我做的第一件事就是打印矩阵阴影:
void separateMatrixByColumn (size_t wanted_cols1, size_t wanted_cols2, size_t rows, size_t columns, int m[rows][columns], int answer1[rows][wanted_cols1], int answer2[rows][wanted_cols2]){
// this print looks bad. It adds several 0s to the matrix!
int k;
int l;
for (k=0; k<rows; k++){
for(l=0; l<columns; l++){
printf("%d ", m[k][l]);
}
printf("\n");
}
...
}
Turns out the print inside of my function looks bad. 结果我的功能内部打印看起来很糟糕。 It shows several 0s inside of my matrix.
它在我的矩阵中显示了几个0。 Why is this happening?
为什么会这样?
I ended up using an additional amtrix 我最终使用了另一个amtrix
int aux[rows][cols];
for (i=0; i<rows; i++){
for(j=0; j<cols; j++){
aux[i][j] = shadows[0][i][j];
}
}
separateMatrixByColumn(1, cols-1, rows, cols, aux, v[0], g[0]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.