int matrix with pointers in C - memory allocation confusion

后端 未结 7 1320
春和景丽
春和景丽 2020-12-18 05:01

I\'m having some issues with producing an int matrix without creating memory leaks. I want to be able to make a given (global) matrix into any size dynamically via read_matr

7条回答
  •  感情败类
    2020-12-18 05:45

    You only freed the first row (or column) of first_matrix. Write another function like this:

    void free_matrix(int **matrix, int rows)
    {
        int i;
        for(i=0; i

    You might want to make the matrix into a struct to store it's row and column count.

提交回复
热议问题