Help wanted with array of pointers to structs 
Author Message
 Help wanted with array of pointers to structs

I hope someone can help me !!

I have a function as follows ;

void log_calls ( int run_length )
{
        ~~~~~~~
        ~~~~~~~
        ~~~~~~~

Quote:
}

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 ?
2.  How does the return statement look ?
3.  How do I call the function ?

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



Sun, 26 Nov 2000 03:00:00 GMT  
 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]);

- Show quoted text -

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



Sun, 26 Nov 2000 03:00:00 GMT  
 Help wanted with array of pointers to structs

: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 ?
=======
none; but you need <stdlib.h> to malloc() and free() the
storage.  And you don't "return" the array of pointers.
=======

:2.  How does the return statement look ?
=======
     }
=======

:3.  How do I call the function ?
=======
    log:_calls(some_int);
=======
: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



Sun, 26 Nov 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. struct.array works - struct->pointer not

2. Help: Pointer to 2-D array of structs.

3. Pointer to a struct within an array Help Please

4. Help: Pointer to 2-D array of structs.

5. array of pointers to array of structs

6. qsorting & managing struct arrays, pointer arrays

7. pointers to functions in structs which take a pointer to that struct as an arg

8. cast pointer to struct to pointer to type of first member of struct

9. VC7.1 - Error C2059 - pointer to array of structs

10. Array of struct Pointers

11. array of struct pointers?

12. array of pointers to struct

 

 
Powered by phpBB® Forum Software