c - 使用 uint8_t 数据的 int 类型矩阵在传递给函数时打印错误

标签 c function matrix int uint8t

好的,我得到了以下指针 sh 和矩阵阴影数组。

 uint8_t * sh;
 int shadows[k][330][210];

我像这样填充阴影:

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++;
        }
}

然后我可以像这样打印阴影[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");
}

到目前为止一切正常。阴影[0]的打印看起来不错。 然后我将此矩阵传递给如下函数:

separateMatrixByColumn(1, cols-1, rows, cols, shadows[0], v[0], g[0]);

在该函数内部,我做的第一件事是打印矩阵阴影:

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");
    }

   ...

}

结果我的函数内部的打印看起来很糟糕。它在我的矩阵内显示了几个 0。为什么会发生这种情况?

最佳答案

我最终使用了额外的 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]);

关于c - 使用 uint8_t 数据的 int 类型矩阵在传递给函数时打印错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56517241/

相关文章:

你能使 C 中的函数参数指向一个变量吗?

c++ - 动态矩阵和 C++ : Segmentation Fault

c - 如何在 header 中使用静态函数并与 float 组进行比较

C++ 代码和来自 C 的对象?

Excel自带函数: Compile error: Sub or Function not defined

c++ - 如何使用vector <vector <int >>找到严格位于矩阵次对角线上的元素之和?

c++ - 错误 : cannot bind non-const lvalue reference of type ‘bool&’ to an rvalue of type ‘bool’

c - 在嵌入式目标上FLASH的m_text内存区域中保留内存空间

计算大数的生日概率

javascript - jQuery:如何使用函数的返回值到另一个函数