Code:
char* wrdArray[5];
for (int count = 0; count < 5; count ++)
{
wrdArray[count] = new char[10];
}
strcpy(wrdArray[0], "Here is the first string."); //Bufferoverflow
Code:
char* wrd[5] = { "these", "words", " need", "memory", "???" };
There is a const missing.
Code:
const char* wrd[5] = { "these", "words", " need", "memory", "???" };
Fine.Now you have an array of 5 constant char pointer,with memory allocated by the compiler,so don't call free on it.
You can copy the array
Code:
char *myWrds[5];
for(int i = 0;i < 5;i++)
{
myWords[i] = new char[strlen(wrd[i]) + 1];
strcpy(myWrds[i],wrd[i]);
}