0

Hello everyone!! I have a problem about memory allocation, i use calloc() to initialize all elements in array to be zero.

This is my code:

```
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#define sizes 1200
main()
{
double** arr;
int m[sizes];
int i,j,k;
srand((unsigned)time(NULL));
arr= (double **) calloc(sizes,sizeof(double*));
for(k=0; k< sizes; k++){
arr[k]=(double*)calloc(sizes,sizeof(double));
}
for(j=0; j< sizes; j++){
m[j]= 0;
while(m[j] <30){
i= (int) rand()%1200;
if (arr[i][j] == 0.0) {
arr[i][j]= (double) rand()/RAND_MAX;
if(arr[i][j] > 0){
m[j]++;
printf("arr[%d][%d] = %lft", i, j, arr[i][j]);
printf("n");
}
}
}
}
// FREEING MEMORY
// for (k = 0; k<sizes; i++) {
// free(arr[k]);
// }
free(arr);
getch();
}
```

My problem is the result of this code was show only some data not the hold data. Could anyone plz help me what's wrong with my code?

Thanks in advance!

*Edited 4 Years Ago by km2011*: i'm typing wrong