simple array of char array problem
hi all,
I have a global array of char array like so
Code:
char *myArray[100];
I then set initialise it with memset
Code:
memset(myArray, '\0', sizeof(myArray));
Now the problem is that I have a function which is called multiple times which assigns strings the myArray like so (obviously this is a simplified version)
Code:
void myArrayAssignment(int i){
char buf[] = "hello world";
myArray[i] = buf;
}
Now the problem is that when I leave the myArrayAssignment function the variable "buf" becomes out of scope so the indexs of myArray all point to junk.
I will need to change myArray from
Code:
char *myArray[100];
to the form of something like this:
Code:
char myArray[100][256];
But i dont know how to assign to the array because C++ doesnt allow for array to array assignments.
Is there away to do this strcpy()?
Thanks