Hello Everyone (again).
I hate to be a pest, but I have a segment of code that I need a little guidance with.
I basically have a dynamic array that I am inserting strings into. Upon assignment everything looks fine. It is when I wish to iterate through the array members that my program crashes.
char ** image_ranges = NULL; // holds all image ranges to use
... later on in the program ...
Basically I take a string like A0100-103 .. break it out to
A0100, A0102, A0103 and insert each piece into the array
_itoa( beg_num, begin_number, 10);
number_length = strlen(image_prefix) + strlen(zero_pad) + strlen(begin_number) + 5;
// allocate space in the image_ranges array and insert image into array
image_ranges = (char**) realloc (image_ranges, (image_ranges_index +number_length) * sizeof (char * ) ); // create space for a pointer to the image
image_ranges[image_ranges_index++] = _strdup(image_prefix) ; // allocate space for the image and store a pointer to it into the image_ranges array
strcat( image_ranges[image_ranges_index-1] , zero_pad );
strcat( image_ranges[image_ranges_index-1] , begin_number );
strcat( image_ranges[image_ranges_index-1] , ".txt\0" );
The above code appears to work. It is when I try to iterate through the members that I get a problem.
int counter;
for(counter = 0; counter < image_ranges_index; counter++){
printf(" \n Removed :: %d :: %s \n", strlen(image_ranges[counter]), image_ranges[counter] );
free(image_ranges[counter]);
}
The members like E100 do not print all of the characters. I have tried increasing the size of the realloc call but it does not work. I noticed that if I do a strlen of the set I iterate through it is one less than it should be.
Am I just missing some simple thing here?
Please let me know if more information is required.
Many thanks for any help that can be provided.