I tried using (*game_data.blocks), (game_data.*blocks), (game_data.blocks) but none of them work.

I'm getting a error msg: 'cannot convert sprites* to sprite_data** in assignment'
-----------------------------------------------------------

typedef struct{
 //sprite _sprites[];
 sprite *blocks;
 sprite ball;
 sprite paddle;
 int numb_brick_sprites;
}sprites;

----------populate_bricks procedure-------------

void populate_bricks(sprites &game_data){
  game_data.numb_brick_sprites++;
 sprites *temp_ = (sprites*) realloc(game_data.blocks, game_data.numb_brick_sprites * sizeof(sprites));
 if(temp_ != NULL) {
 game_data.blocks = temp_; //getting error msg here: cannot convert sprites* to sprite_data** in assignment
 }
 else {
 printf("Error creating bricks...\n");
 return;
 }
}

-----------------main function------------

int main(){
	sprites game_data;
	game_data.blocks = NULL;
	game_data.numb_brick_sprites = 0;
	initialise_game(bitmap_names, game_data);
}

Thanks

How are you calling - void populate_bricks(sprites &game_data)?

Hi, thanks for replying.

From the main function I am passing game_data to initialise_game procedure:
initialise_game(bitmap_names, game_data);

In initialise_game procedure I am passing game_data to populate_bricks procedure:
populate_bricks(game_data);

I'm getting a error msg: 'cannot convert sprites* to sprite_data** in assignment'

Your name choices are confusing you. blocks is defined as being a pointer to sprite , which the error suggests is a typedef for a pointer to sprite_data . This is very different from the sprites typedef, which is a synonym for the structure that owns the blocks member.

What you need to do is allocate memory for the correct type:

sprite *temp_ = (sprite*)realloc(game_data.blocks, game_data.numb_brick_sprites * sizeof(sprite));

Thanks Narue,

My program is compiling now :)

I'm learning dynamic arrays and struct, so thats why its still a bit confusing to get my mind around this.

Thanks.

I'm learning dynamic arrays and struct, so thats why its still a bit confusing to get my mind around this.

It will probably help if you don't hide levels of indirection behind a typedef. The only way I knew that sprite was a typedef is from the error; it mentions sprite_data** , which suggests that sprite is defined as:

typedef sprite_data *sprite;

Thus when you say sprite *blocks , you're really saying sprite_data **blocks . That hidden * is significant, and can confuse a lot of readers of your code (most notable among them being you). A better option is making all levels of indirection explicit:

typedef sprite_data sprite;

typedef struct {
    sprite **blocks;
    sprite *ball;
    sprite *paddle;
    int numb_brick_sprites;
} sprites;

Though that wouldn't necessarily help you avoid the problem from this thread, which was confusing "sprite" and "sprites".

I will do this from now on.

I was wondering where sprite_data was coming from because I couldn't find it in my code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.