c - malloc debugging...solution needed -
c - malloc debugging...solution needed -
typedef struct nodes* nods; struct nodes { int field,grammi,stili,flag1,flag_gv,height; nods d,r,l,u; };
. . .
int j; struct nodes kefelement[30]; kefelement=(nods)malloc(30*(sizeof(struct nodes))); ((j=0); (j<30); j++) { kefelement[j].r=null; kefelement[j].d=null; kefelement[j].grammi=j+1; kefelement[j].stili=j+1; kefelement[j].field=0; kefelement[j].u=null; kefelement[j].l=null; kefelement[j].flag1=0; kefelement[j].flag_gv=0; kefelement[j].height=0; }
the problem malloc....someone pls help me!!!!
struct nodes kefelement[30]; kefelement = (nods)malloc(30*(sizeof(struct nodes)));
kefelement
array. compiler allocate part of memory can accessed through name kefelement
. note name not pointer can assigned new value. however, using kefelement
in look (with exceptions) translate name pointer first element.
if want allocate dynamic memory array, need declare pointer:
struct nodes *kefelement; kefelement = (nods)malloc(30*(sizeof(struct nodes)));
or better:
kefelement = malloc (30 * sizeof *kefelement);
the lastly version automatically allocates right amount of memory, regardless of pointer points to. (nods)
cast not necessary in c.
c malloc
Comments
Post a Comment