I think you mean to use a sentinel value on your struct, instead of using a length property, right?
Take a look on my attempt to fix it:
typedef struct sprites_s {
bool initialized; // removed pointer
sfSprite *duck;
} sprites_t;
int create_sprite(sprites_t **sprites) {
size_t memoryNeeded = sizeof(sprites_t) * MAX_SPRITE_DISPLAYED;
sprites_t *arr = malloc(memoryNeeded);
// Never forget to check if malloc returns NULL.
if (arr == NULL) {
return 0;
}
// Instead of:
// memset(*sprites, NULL, sizeof(sprites_t));
//
// or
// memset(arr, NULL, sizeof(sprites_t));
//
// Do this:
sprites_t template;
template.initialized = true;
template.duck = NULL;
for (size_t i = 0; i < MAX_SPRITE_DISPLAYED-1; ++i) {
memcpy(&(arr[i]), &template, sizeof(sprites_t));
}
// And then, for the last one to mark as a sentinel value:
//
// You could do it like this:
// *sprites[MAX_SPRITE_DISPLAYED - 1] = (sprites_t) {
// false,
// NULL
// };
//
// But I think this is better:
template.initialized = false;
memcpy(&(arr[MAX_SPRITE_DISPLAYED-1]), &template, sizeof(sprites_t));
// Then, everything went as expected, you can return both values
*sprites = arr;
return 1;
}
Note: I didn't compiled the code. If there're typos, my bad.