If you want an array of pointers, you should do:
Tproduct **arrayOfPointers = (Tproduct**)malloc(N*sizeof(Tproduct*));
This code does exactly what you want - allocate memory for N Tproduct pointers.
What's wrong with your code?
Your type of arrayOfPointers is a pointer to Tproduct - so, you can manipulate it like1 an array of objects, but not like an array of pointers to the objects.
1 It's still a pointer, not an array. That's why like.
In case you want an array of objects, you should allocate memory for N objects, not N pointers:
malloc(N * sizeof(Tproduct))
// ^^^^^^^^ - Note: not a pointer
And now I want to write a function returning an array of this type. What's the prototype?
Tproduct** fill();
Should do the work. Example of function:
Tproduct** fill()
{
Tproduct **arrayOfPointers = (Tproduct**)malloc(N*sizeof(Tproduct*));
// do some stuff
return arrayOfPointers;
}
But I suggest rename your function to, say, allocate_array or something like this. fill doesn't mean allocate.