【问题标题】:problem with entering numbers into the matrix [duplicate]将数字输入矩阵的问题[重复]
【发布时间】:2019-09-02 07:33:59
【问题描述】:

在矩阵中输入数字时的断言问题

我已经检查了矩阵是否已正确分配

matrix = alloc_matrix(row, cols);
printf("enter number to matrix\n");

int i, j;
for (i = 0; i < row; i++)
{
    for (j = 0; j < cols; j++)
    {
        scanf_s("%d", matrix[i][j]);
    }
}
void main() {
    int row, cols;
    int **matrix;
    printf("pleaese enter a row \n");
    scanf_s("%d", &row);
    printf("pleaese enter columns\n");
    scanf_s("%d", &cols);
    matrix = alloc_matrix(row, cols);
    printf("enter number to matrix\n");
    int i, j;
    for (i = 0; i < row; i++) {
        for (j = 0; j < cols; j++) {
            scanf_s("%d", matrix[i][j]);
        }
    }
    system("pause");

}

断言失败

【问题讨论】:

  • alloc_matrix 是什么?其他代码在什么功能中?它在哪里失败了断言?请发布整个代码,或者更确切地说是Minimal, Reproducible Example

标签: c matrix


【解决方案1】:

我认为问题出在线路上

scanf_s("%d", matrix[i][j]);

scanf_s 需要该矩阵项的地址(假设您有一个二维整数数组)。

所以更多的东西

scanf_s("%d", &matrix[i][j]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-05
    • 1970-01-01
    • 2022-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-05
    • 1970-01-01
    相关资源
    最近更新 更多