Help wanted with array of pointers to structs
See in text....
Quote:
> I hope someone can help me !!
> I have a function as follows ;
> void log_calls ( int run_length )
> {
> ~~~~~~~
> ~~~~~~~
> ~~~~~~~
> }
> The function declares and initialises an array of pointers to
> structures (the structure is global and is called 'call')
> My questions :
> 1. What header do I need to return the array of pointers to structs ?
typedef struct calls Calls;Calls ** log_calls(int len)
Quote:
> 2. How does the return statement look ?
Inside function declare var of type Cals **:Calls * myCalls[len];
allocate the space for each elt of array:
for(.....) {
myCalls[i] = mallo(sizeof(Calls));
Quote:
}
return myCalls;
Quote:
> 3. How do I call the function ?
Calls ** retCalls;retCalls = log_calls(total_calls_to_be_allocated);
for( i=.....) {
free(retCalls[i]);
Quote:
}
> Any help would be much appreciated. I have been told I can declare
> the array to be global - but I want to avoid this if at all possible.
> Regards,
> Lee