HELP -> dynamic array of char** in dynamic array of mystruct** 
Author Message
 HELP -> dynamic array of char** in dynamic array of mystruct**

 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

Wed, 02 Jul 1997 23:24:23 GMT  
 [ 1 post ] 

 Relevant Pages 

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

2. HELP! dynamic array of char*

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

4. finding chars in dynamic arrays

5. How to populate a dynamic array of strings (char*)

6. HELP -> dynamic char** arrays (inside a dynamic struct**)

7. How to inspect dynamic array ( my_struct* array) ?

8. Control Arrays/Dynamic Arrays

9. Lists VS. Dynamic Arrays VS. Re-defining Arrays

10. Usage of sizeof(<dynamic array>)

11. dynamic array - newbie help

12. dynamic array help


Powered by phpBB® Forum Software