I'm making a linked list (of structs) in C, but I want to be able to call a function and have it add 4-5 stucts to the list by itself. The problem is since in C all the variables created in functions are left on the stack/heap I have no clue how I am supposed to accomplish this.
Here is a code example:
struct listItem
{
int value;
listItem *left;
listItem *right;
}
void addItems(listItem *l)
{
listItem one, two, three;
l->left = &one;
one.left = &two;
two.left = &three;
}
int main (char *a [])
{
listItem l;
addItems(l);
}
Obviously this will not work. How might I accomplish this? Is it even possible. Thanks
EDIT: Wow thank you everyone for the help. That was faster and more helpful than I could have imagined!