I currently have an array of char*
's. I am trying to use strcpy
to assign each element in this array the current string being processed. I have managed to do this with a 2D array of chars (char[][]
). However, I want to accomplish this with an array of character pointers because I don't want to define the size of the array at compile time. Is there anyway to have something like the following code?
n = 5;
char* test[n];
strcpy(test[0], "random string");
I understand that strcpy does not work with character pointers which are uninitialised and have looked into using memset
. However, I'm hoping for a more elegant solution.