I have a function which takes a structure as a parameter, like:
add_new_structure(structure s);
then store it inside
structure structure_list[200];
question:
1. when I want to use the structure, I have a function like
structure *getStructure(int id)
{
return &structure_list[id];
}
is it gonna work if I add one structure like this:
void init()
{
structure test;
memset(&test,0,sizeof(structure));
add_new_structure(test);
}
and then call getStructure from another function? like this:
void anotherFunction()
{
structure *got_test = getStructure(0);
}
because I remember I can't have local variable and then call it from another function right?
2.is it better to just store it like this?
change the add_new_structure() parameter to structure *s
;
then store it inside
structure *structure_list[200];
by calling add_new_structure(&test);
3. which one is better? or what is the right way to do it?