fork download
#include 
#include 


typedef struct ENTITY
{
    char * field1;
    char * field2;
} entity;

int my_function(entity ** my_array)
{
    int  count = 14;

    entity * result;
    result = (entity *) calloc(count, sizeof(entity));

    int i;
    for(i = 0 ; i < count ; i++)
    {
        (result+i)->field1 = strdup("Blabla in field1");
        (result+i)->field2 = strdup("Blabla in flied2");

        // This line print correctly "Blabla in field1" for each element in the array.
        printf("->{%s}\n", (result+i)->field1);
    }

    *my_array = result;
    return count;
}

int main()
{
    	entity * my_array;
	int count = my_function(&my_array);
	int i=0;
	for(i = 0 ; i < count ; i++)
	{
    		printf("field1 of the element %d: %s\n", i, my_array[i].field1);
	}
	return 0;
}
Success #stdin #stdout 0.01s 1852KB
stdin
Standard input is empty
stdout
->{Blabla in field1}
->{Blabla in field1}
->{Blabla in field1}
->{Blabla in field1}
->{Blabla in field1}
->{Blabla in field1}
->{Blabla in field1}
->{Blabla in field1}
->{Blabla in field1}
->{Blabla in field1}
->{Blabla in field1}
->{Blabla in field1}
->{Blabla in field1}
->{Blabla in field1}
field1 of the element 0: Blabla in field1
field1 of the element 1: Blabla in field1
field1 of the element 2: Blabla in field1
field1 of the element 3: Blabla in field1
field1 of the element 4: Blabla in field1
field1 of the element 5: Blabla in field1
field1 of the element 6: Blabla in field1
field1 of the element 7: Blabla in field1
field1 of the element 8: Blabla in field1
field1 of the element 9: Blabla in field1
field1 of the element 10: Blabla in field1
field1 of the element 11: Blabla in field1
field1 of the element 12: Blabla in field1
field1 of the element 13: Blabla in field1