How do I return an array of struct from a function? Here\'s my work; it\'s pretty simple to understand. I\'m unable to return the array items so that it can be used in the
struct Operator fun()
{
struct Operador items[3];
...
return items[n];
}
You cannot return a local-defined array of structs defined in an automatic variable. And what you do in your case, you return items[n] for an n where items was not initialized.
you can return an array only if you allocate it on the heap and you can do something so:
struct Operator *fun(int k)
{
struct Operador *items = malloc(sizeof(struct Operator) * k);
int n;
for(n=0;n