c - Problems with deallocation of double pointer and pointer -


hi have problems in code:

this matrix allocation function:

matrix_type** matrix_allocation(matrix* matrix, int* rows_size, int* cols_size) //this function allocates dynamically matrix , verify allocation {     int i;     matrix->n_rows=0;     matrix->n_cols=0;     matrix->pp_matrix=(matrix_type**)calloc(*rows_size,sizeof(matrix_type*));     i=0;     while(i<*rows_size)     {         matrix->pp_matrix[i]=calloc(*cols_size,sizeof(matrix_type));         i++;     }     matrix->n_rows=*rows_size;     matrix->n_cols=*cols_size;     return matrix->pp_matrix; } 

this deallocation function:

void matrix_deallocation(matrix* matrix) //this function deallocates matrix {     int i;     i=0;     while(i<matrix->n_cols)     {         free(matrix->pp_matrix[i]);         i++;     }     free(matrix->pp_matrix); } 

where matrix struct is

typedef int matrix_type; typedef struct{     int n_rows;     int n_cols;     matrix_type** pp_matrix; }matrix; 

how call deallocation function in main:

matrix_deallocation(&table); 

this function deallocate half matrix, why?

screen

it seems mean following

void matrix_deallocation(matrix* matrix) //this function deallocates matrix {     ( int = 0; < matrix->n_rows; i++ )     //                           ^^^^^^      {         free( matrix->pp_matrix[i] );     }     free(matrix->pp_matrix); } 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -