I allocate memory for the array. I read the data from the file, and I either crashes, or zeros or strange numbers appear. Confused with the release of memory ... (
#include <stdio.h> #include <stdlib.h> #include <math.h> double **A; int n_A, m_A; int i, j; void read_matrix(const char *filename) { FILE *file = fopen(filename, "r"); /* m_A - число строк, n_A - число столбцов */ fscanf(file, "%d %d", &m_A, &n_A); A = (double **)malloc(n_A * sizeof(double *)); if (A != NULL) { for (i = 0; i < m_A; i++) { A[i] = (double *)malloc(n_A * sizeof(double)); if (A[i] != NULL) { memset(A[i], 0, n_A * sizeof(double)); free(A[i]); } fscanf(file, "%lf", &A[i][j]); } } } int main(int argc, char *argv[]) { clrscr(); read_matrix("data 2.dat"); free(A); getch(); return 0; }