It has taken me a while to figure it out, but in the end...
Here's the working code:
void copyToArray(char **arrayPtr, const char *strPtr)
{
*arrayPtr = (char*) malloc(sizeof(char) * 20);
strcpy(*arrayPtr, strPtr);
}
int main(int argc, const char * argv[])
{
char *myA[3] = {"First string", "Second String", "Third string"};
char strOne[20] = "";
char strTwo[20] = "Hello my dear";
char *ptrStrOne = NULL;
ptrStrOne = strcpy(strOne, strTwo);
copyToArray(&myA[1], ptrStrOne);
//myA[1] = ptrStrOne;
printf(" myA[1]: |%s|\n", myA[1]); // |Fifth string|
printf("*myA[1]: |%c|\n", *myA[1]); // |F|
printf("&myA[1]: |%p|\n\n", &myA[1]); // |0x7ffeefbff3f8|
ptrStrOne = strcpy(strOne, "&");
printf(" myA[1]: |%s|\n", myA[1]); // |&|
printf("*myA[1]: |%c|\n", *myA[1]); // |&|
printf("&myA[1]: |%p|\n\n", &myA[1]); // |0x7ffeefbff3f8|
for (int i = 0; i < 3; i++)
{
printf("String: |%i| is: |%s|\n", i, myA[i]); // |Fifth string|
}
return 0;
}
Output:
myA[1]: |Hello my dear|
*myA[1]: |H|
&myA[1]: |0x7ffeefbff3f8|
myA[1]: |Hello my dear|
*myA[1]: |H|
&myA[1]: |0x7ffeefbff3f8|
String: |0| is: |First string|
String: |1| is: |Hello my dear|
String: |2| is: |Third string|
Program ended with exit code: 0
Now I'm able to update/attach to strOne as much as I like and copy the contents of strOne to and element of the array.