I am using the following code and in line "arr[0]->p = (int *)malloc(m * sizeof(int));"I have "Segmentation fault (core dumped)". I need to write my code in this way...
Can someone help how can I write this and why my code have this error?
#include <stdio.h>
#include <stdlib.h>
typedef struct data{
int *p;
}data;
void main(){
int n = 10,
m = 5 ;
data **arr = (data**)malloc(n * sizeof(struct data*));
arr[0]->p = (int *)malloc(m * sizeof(int));
}
something like this it works
/************************************************************
* *
* data *arr = (data*)malloc(sizeof(struct data)); *
* arr->p = (int *)malloc(m * sizeof(int)); *
* *
*************************************************************/