I have an array of strings defined like this:
char** arrNames;
Now I want to dynamically allocate a size to it.
I have a function that receives the new size and the array above.
It goes like this:
char** AddName(char** arrNames, int nNameCount)
{
char** arrTemp;
arrTemp = new char[nNameCount];
...
// And later I change the pointer of arrNames to arrTemp
}
Now this obviously doesn’t work. So what should I be doing instead?
Thanks in advance.
If you want nNameCount strings, you need to allocate an array of arrays of chars (i.e an array of strings):
After this you can access each string with arrTemp[index]. Note that you still need to initialize each string.