I am trying to create dynamically an array of structs . Although with small sizes seems to work fine but the program crushes later(segmentation fault ) . When in have a big ipt_size it crushes very fast with nosense numbers so i assume the problem is in the way i allocate my array.
int create_ipt(int ipt_size,frame **ipt){
int i;
*ipt=malloc(ipt_size*sizeof(frame*));
for(i=0;i<ipt_size;i++){
ipt[i]=malloc(sizeof(frame));
if (ipt[i]==NULL) return 1; //error
ipt[i]->empty=1;
}
return 0; //success
}//create page table
I call the function with
frame *ipt;
create_ipt(ipt_size,&ipt);
Do you know what's happening ? frame has 3 ints inside
*ipt=malloc(ipt_size*sizeof(frame*));
-->*ipt=malloc(ipt_size*sizeof(frame));
..if (*ipt==NULL) return 1; for(i=0;i<ipt_size;i++){ (*ipt)[i].empty=1; }