When doing my project I've came across to a problem. I It seems like realloc
is not copying all data from original array. This is what I'm dealing with (code still missing error checking, I know) :
char ** dictionary = (char**) malloc(512 * sizeof(char*));
for (int i = 0; i < 256; i++)
{
dictionary[i] = (char*) malloc(2 * sizeof(char));
sprintf(dictionary[i], "%c", i);
}
char * character = dictionary[129];
char ** new_dictionary = realloc(dictionary, 1024);
dictionary = new_dictionary;
char * character2 = dictionary[129];
I first create a array of pointers to char pointers. Then I create pointer to array of chars for each byte and assign byte value. Values of character
and character2
differ. Why? I've checked for lower and higer indexes (few samples) and the values remains the same. Does this have something to do with that I'm trying to realloc
char pointers not just pure data?