Hi, I'm just getting started with structures on C and they don't seem to bad but my main question is about pointers to structures.
Basically I have a structure containing a vector array and length and 'vs' has to be a pointer to a structure of this sort. So I defined 'vs' as such:
Code:
typedef struct
{
vector arr[100];
int length;
}ps, *vs;
where vector is:
Code:
typedef struct
{
int x;
int y;
}vector;
I have a function that makes pointers of structures of type 'vs' but I'm not sure on how to set it up. The way only way I could think of it was to make a structure of the same type as '*vs' called 'ps' and initialize 'ps' thus making 'vs' = the address of the initialized 'ps' like so:
Code:
vs *make_vs ()
{
ps strt = {{0,0},0}; // initializing instance of structure 'ps'
vs *ptr; // declaring instance of '*vs'
ptr = &strt; // setting ptr to the address of 'strt'
return ptr; // returning pointer of type 'vs'
}
I'm really not sure if I'm going about this the correct way. I basically just want to created a new instance of the structure defined above and return a pointer to that structure.
Such that I can utilize it like so:
Code:
vs a = *make_vs (); // or however I am supposed to create a new instance
The ultimate goal is to create these 'vs' pointers and be able to add/remove/get vectors from the array the structure holds. If that made any sense to anyone, could you please enlighten me or point me in the right direction?
Thank you