Pointer to an array definition can not be compiled

I can not compile the following code, and I cannot figure out why.
1
2
3
4
char* charArray[3];
    strcpy(charArray[0],"wn");
	strcpy(charArray[1],"chair");
	strcpy(charArray[2],"-over");

Thanks for helping me out!
You should be able to compile that. And then it should break, since values in charArray are not initialized. If you want to use c libraries, do charArray[0] = malloc(strlen("wn")+1); strcpy(charArray[0], "wn"); and so on. But if you can, use std::string. That would make things easier.
First that is a bad idea since there is no memory allocated for the destination. charArray hasn't been initialized with pointers to valid memory blocks in the first place. If you want the array to be initialized to string literals you can do this.
 
const char* charArray[3] = { "wn", "chair", "-over" };


or this

std::string charArray[3] = { "wn", "chair", "-over" };
I don't have any syntax error before this code, but yet after I wrote the definition line for the pointer array, I get the following one:

syntax error : missing ';' before 'type'

If the code that I posted is commented out, there are no compilation errors. What can possibly be wrong, especially now after I added the malloc code before each strcpy command. And the malloc allocates memory for each word separately into a new element of the array.

Thanks for the help hamesterman!
Topic archived. No new replies allowed.