0

Hi,

I am have trouble in Array of pointers to structure.
I have defined as structure.
typedef struct
{
char * name[5];
int number;
}mystr;

I have defined an array of pointers to this structure.( is this correct ?)
mystr (* myptr)[5];

To fill the values, i have to pass this to a function, fill it and return it back.
Now I have to
1) pass this array of pointers to structure as an arugument to a function ( i dont know how?)
2) get it filled up ( i guess i can do)
3) return the array of pointers to structure to the calling function ( i dont know this either.)

I am getting rather confused to make a function definition for this.
Hope somebody could through some light abt this.
Thanks.
Vib.

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
0

To pass that array. Note: name in the structure is an array is 5 pointers, not a character array. So that structure can hold up to 5 strings (names).

typedef struct
{
char * name[5];
int number;
}mystr;

int foo(mystr* myptr[5])
{
    return 0;
}

int main()
{
    mystr* myptr[5];
    foo(myptr);


}

2) full it up as you normally would in main()

3) Not necessary ot specifically return the array back to main because when its changed in foo() it will also be changed in main().

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.