I am doing something like following;
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
double **arr;
}communication;
int main()
{
int r = 3, c = 4, i, j, count;
communication *comm;
comm->arr = (double **)malloc(r * sizeof(double *));
for (i=0; i<r; i++)
comm->arr[i] = (double *)malloc(c * sizeof(double));
count = 1;
for (i = 0; i < r; i++)
for (j = 0; j < c; j++)
comm->arr[i][j] = count*2.0;
for (i = 0; i < r; i++)
for (j = 0; j < c; j++)
printf("%lf ", *(comm->arr[i]+j));
return 0;
}
It is giving me seg fault error. Please tell me how can I define a 2D array through double-pointer method with structure just like I am trying to do in above code?