
Need help with array realloc's
Quote:
>Hi, can you help?
>char array[128][]=NULL;
You are trying to define an array of arrays of indetermined size. An
array of indetermined size is an incomplete type. Since the size of
each element of array is indetermined, an array of them will not work.
Your intention might be something like
char (* array)[128] = NULL;
i.e. a pointer to arrays of 128 chars.
Quote:
>.or.
>struct element
>{
> char word[128];
>} *array;
>I need to initialize 'array' and then, as it grows due to incomming
>data, I need to 'realloc'. Any examples?
unsigned n = 0;
char (* array)[128] = NULL;
/* To grow: */
char (* tmp)[128] = realloc(array, ++n * sizeof *tmp);
if (tmp)
array = tmp;
else
/* Handle allocation error */
Kurt
--
| Kurt Watzka Phone : +49-89-2180-6254