[Solved] How to shrink at runtime a struct matrix (using realloc() for example)
You should reduce the number of columsn, not rows. Not mat1 but mat1->array should be reallocated. Not nrow and ncol (not updated) but mat1->nrows and mat1->ncols (updated) should be used for the new size. The elements are size_t, so allocating for int mayn’t be enough. Using the variable for calculating size is safe. In the … Read more