Hi,
I am getting segmentation error with below-mentioned code and I am not
able to make out why.
typedef struct sd {
int ps;
int cs;
} st;
void main()
{
st **fe;
int n,j;
n = 11;
fe = (st **) calloc(n+1, sizeof(st *));
for (j=0; j<=n; j++)
fe[j] = (st *) calloc(16, sizeof(st));
for (j=0; j<=n; j++)
free(fe[j]);
free(fe);
}
When I tried to debug with gdb, it is pointing to fe[j] = (st *)
calloc(16, sizeof(st));
Please suggest.
Regards,
JK
I am getting segmentation error with below-mentioned code and I am not
able to make out why.
typedef struct sd {
int ps;
int cs;
} st;
void main()
{
st **fe;
int n,j;
n = 11;
fe = (st **) calloc(n+1, sizeof(st *));
for (j=0; j<=n; j++)
fe[j] = (st *) calloc(16, sizeof(st));
for (j=0; j<=n; j++)
free(fe[j]);
free(fe);
}
When I tried to debug with gdb, it is pointing to fe[j] = (st *)
calloc(16, sizeof(st));
Please suggest.
Regards,
JK
Comment