-3

assertion problem when I entering numbers into the matrix

I've already checked that the matrix has been properly allocated

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

}

assertion failed

Blaze
  • 16,736
  • 2
  • 25
  • 44
yona869
  • 3
  • 3
  • 1
    What's `alloc_matrix`? What function is that other code in? Where is it failing the assertion? Please post the whole code, or rather a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Blaze Sep 02 '19 at 07:37

1 Answers1

4

I think the problem is with line

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

scanf_s needs the address of that matrix item (assuming you have a 2D array of integers).

So something more in the lines of

scanf_s("%d", &matrix[i][j]);
E. van Putten
  • 615
  • 7
  • 17