I have something being returned as a const char* and would like to save it to an array.
I've tried this:
const char* book[amtBooks] = "";
and get this error:
error: array must be initialized with a brace-enclosed initializer
const char* book[amtBooks]
is an array of pointers.""
is an array of chars (with only a NUL character).You can initialize an array of chars with an array of chars:
const char foo[] = "hello";
You can also initialize a pointer to char with an array of chars:
const char *bar = "good bye";
this works because of the “decay to pointer” feature of C and C++.
But initializing an array of pointers with an array of chars simply does not make sense. An array of pointers to char could be initialized as
const char *book[] = {"hello", "good bye"};
const char* book[amtBooks] = { NULL };
. This will initialize every book to a null pointer.