Need help with array realloc's 
Author Message
 Need help with array realloc's

Hi, can you help?

char array[128][]=NULL;

.or.

struct element
{
        char word[128];

Quote:
} *array;

I need to initialize 'array' and then, as it grows due to incomming
data, I need to 'realloc'.  Any examples?

Thanks;




Fri, 12 Feb 1999 03:00:00 GMT  
 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



Sun, 14 Feb 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. trouble with realloc'ing array of char *'s

2. realloc'ing 2D arrays, how?

3. Need help with array's

4. problem realloc array inside array of struct

5. problem realloc array inside array of struct

6. need some realloc help..

7. 'Freeing' storage with realloc

8. 'Freeing' storage with realloc

9. NEED HELP WITH PRITING AN ARRAY, PLEASE PLEASE HELP

10. array's of array's

11. Problem with realloc on a 2D-array

12. need 'serialization' help in C

 

 
Powered by phpBB® Forum Software