Vote count:
0
My program isen't deleting the arrys, alwais stop at the point whan reaches the freeing pint. My code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main(){
int n,m;
scanf("%d %d",&n,&m);
int** t;
t=(int**)malloc(n);
for(int i=0;i<n;i++){
t[i]=(int*)malloc(m);
}
for (int i=0; i<n; i++){
for(int j=0; j<m; j++){
t[i][j] = rand() % 10;
printf("%d ",t[i][j]);
}
printf("\n");
}
getch();
for(int i=1;i<n;i++){
free (t[0]);
}
free (t);
return 0;
}
asked 2 mins ago
1 Answer
Vote count:
0
You are trying to free the first element several times, instead free each only once.
for(int i=1;i<n;i++){
free (t[i]);
answered 1 min ago
Freeing malloc 2D matrix
Aucun commentaire:
Enregistrer un commentaire