Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cast pointer to array struct

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Question
how do i cast a pointer to an array of structs

like
struct mystruct * record[MAX];

* func();
*record = ( struct mystruct *) func();


thanks
 
I usually create some new types for Pointers to structs, something like:

Code:
struct Dummy;
typedef struct Dummy T_Dummy;
typedef T_Dummy * PDummy;

struct Dummy {
   int a;
   int b;
};
PDummy* function_that_Returns_an_Array_if_dummies()
{
} 

void * function_that_returns_the_mighty_VOID_STAR()
{
}

main ()
{  PDummy singleDummy = (PDummy )malloc(sizeof(T_Dummy));
   PDummy* multipleDummy = (PDummy *)malloc(sizeof(PDummy)*nrOfElements);

multipleDummy = (PDummy *)function_that_returns_the_mighty_VOID_STAR();

}

Hope this hepls... [red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top