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.
neweven if you happen to be (very unwisely IMO) using a C++ compiler to compile your C code. If you want to learn C++ then in real life don't usenewfor this either, use a vector. For the purposes of understanding how memory allocation works in C++ you could usenewfor this, but if you're supposed to be learning malloc/free for use in C, then you won't do so by using C++ new[]/delete[] instead ;-)