c - Using realloc to resize a dynamic array -
i tried extend ful list of players.
when use reallo
c function, save player except last. mean if had 4 players in array , tried extend array 7 got new array in size 7 , 3 players.
this part of function:
void initializelistfortree(player** players, int listsize) { int formulasize = bla bla bla..... players = (player **)realloc(players, sizeof(player *)*formulasize); if (!players) { printf("memory allocation failed\n"); } }
more like:
void initializelistfortree(player*** players, int listsize) { int formulasize = bla bla bla..... void *p = realloc(*players, sizeof(player *)*formulasize); if (!p) { printf("memory allocation failed\n"); } else { *players = p; } }
and @ call site
player **playerslist = null; initializelistfortree(&playerslist, 1); ... initializelistfortree(&playerslist, 2); etc..
this, of course, if type pointer list of pointers.
Comments
Post a Comment