binaryDigit
11-13-2002, 12:34 PM
i feel stupid for asking this question, but i've succeeded in confusing myself.
an array of character pointers:
char **some_array;
if i want to dynamically allocate space for this i have to do this:
char **a;
/* this part really confuses me. it doesn't seem to matter how much space i allocate */
a = malloc(1)
/* allocating a size of 20 to first item in array */
a[0] = (char *) malloc(20);
a[1] = (char *) malloc(30);
/* do stuff with array */
free(a[0]);
free(a[1]);
/* free a ??? */
so what's the right way to allocate and free the necessary space?
an array of character pointers:
char **some_array;
if i want to dynamically allocate space for this i have to do this:
char **a;
/* this part really confuses me. it doesn't seem to matter how much space i allocate */
a = malloc(1)
/* allocating a size of 20 to first item in array */
a[0] = (char *) malloc(20);
a[1] = (char *) malloc(30);
/* do stuff with array */
free(a[0]);
free(a[1]);
/* free a ??? */
so what's the right way to allocate and free the necessary space?