Saturday, 24 August 2013

Reallocate string array

Reallocate string array

I need to reallocate an array of strings, but the the values of the
strings change whenever I call realloc. Does anyone know why this happens?
(xmalloc = malloc and xrealloc = realloc)
This is how the strings are allocated:
sprite[cur_sprites].states = xmalloc (sprite[cur_sprites].states, sizeof
(unsigned char)*tot_states);
sprite[cur_sprites].png_paths = xmalloc (sprite[cur_sprites].png_paths,
sizeof (char*)*tot_states);
When reallocating:
#ifdef DEBUG
printf ("cur_states = %i\n", cur_states);
for (i2 = 0; i2 < cur_states; i2++) {
printf ("+Object: %i\n", cur_sprites);
printf (" index state: %i\n", i2);
printf (" state: %i\n", sprite[cur_sprites].states[i2]);
printf (" name: %s\n", sprite[cur_sprites].png_paths[i2]);
}

No comments:

Post a Comment