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

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -