Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

java the hut

Name: Anonymous 2010-10-13 22:41


int i;
char **x = malloc(sizeof(char *) *600);
for(i=0;i<600;i++)
    x[i] = malloc(sizeof(char) * 500);

//do some work


for(i=0;i<600;i++)
    free(Counter[i]); //error
free(Counter);


what did i do wrong?

Name: Anonymous 2010-10-14 6:39

If the text rows are always of the same size {tt m}, then just make one allocation.

{code C

char **x = malloc (n * sizeof *x + m * sizeof **x);
char *y = (char*)(x + n);
for (i = 0; i < n; i++)
    x[i] = y + i*m;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List