I'm working on a program, which should search the registry for specific values, and store them, and their path in an array. So i don't know how many keys the program will find, and therefore i need to use a dynamically growing array. I use this code right now, but i'm not sure if it is correct.
struct data
{
char * Path;
char * Key;
};
struct data **RegArray = NULL;
int ArrayCount = 0;
// ....
// ....
// search the registry here....
// value has been found, so i should add it to the array here
RegArray = ( struct data **)realloc( RegArray, ( ArrayCount + 1 ) * sizeof( struct data *) );
RegArray[ ArrayCount ] = ( struct data *)malloc( sizeof( struct data ) );
RegArray[ ArrayCount ]->Path = _strdup( CurrentPath );
RegArray[ ArrayCount ]->Key = _strdup( CurrentKey );
ArrayCount++;
Could someone tell me please if this could is ok, or not. If not, how should i do it correctly?
Thanks!