HELP -> dynamic char** arrays (inside a dynamic struct**) 
Author Message
 HELP -> dynamic char** arrays (inside a dynamic struct**)

Hi, I have an array of pointers to structures:

mstruct **data;

data = (mstruct**) malloc(arraysize * sizeof(mstruct*)

the above works fine, I use realloc when needed etc.

Inside this structure, (mstruct) I have an array of strings,  I would like to
make this array bigger each time a while loop loops. The string is declared:

char **cars;

My function that has the structure passed to it is as follows:

int counter=0;

        data->cars[i] = read_in_my_data();

My question is how do I allocate memory for this array?

cars = (char**) malloc(arraysize * sizeof(char*))

Is this correct?  Do I then have to allocate memory for each pointer?

cars[i] = (char*) malloc(80)

When I'm done, what do I have to free?  Now I just free my structure:


Do I have to free my pointer to an array of pointers to chars?

Thanx very much in advance.

(Please reply via e-mail if possible)

BTW I have a small program, that creates an array, char **array, and uses it
etc, but when I implement this in my program, my strings go haywire.  Maybe it
is because it is inside the structure.


Alex Black

Tue, 01 Jul 1997 23:21:34 GMT  
 [ 1 post ] 

 Relevant Pages 

1. HELP -> dynamic array of char** in dynamic array of mystruct**

2. help with function to create dynamic two-dimensional char array

3. HELP! dynamic array of char*

4. dynamic linked list + dynamic struct members

5. Dynamic arrays not really dynamic in managec C++?

6. dynamic char * length in a struct

7. Structs with dynamic arrays

8. dynamic pointer array to struct

9. arrays of dynamic size in structs

10. dynamic array of structs

11. Accessing arrays of char pointers inside of structs.

12. finding chars in dynamic arrays


Powered by phpBB® Forum Software