here is my question I have this in my .h file
static const char *Title[];
How do I initialize the array in my .C file the array to lets say "first", "second", "third"
A char array is mostly declared as a fixed-sized structure and often initialized immediately. Curly braced list notation is one of the available methods to initialize the char array with constant values.
Initializing a string constant places the null character ( \0 ) at the end of the string if there is room or if the array dimensions are not specified. The following definitions show character array initializations: static char name1 [ ] = { 'J', 'a', 'n' }; static char name2 [ ] = { "Jan" }; static char name3 [4] = "Jan";
Initialization from strings String literal (optionally enclosed in braces) may be used as the initializer for an array of matching type: ordinary string literals and UTF-8 string literals (since C11) can initialize arrays of any character type (char, signed char, unsigned char)
static const char * const days [] = {"mon", "tue", "wed", "thur", "fri", "sat", "sun"}; Second of all, you can't initialize that directly inside the class definition. Inside the class definition, leave only this: const char * const Week::days [] = {"mon", "tue", "wed", "thur", "fri", "sat", "sun"};
static const char* Title[] = { "first", "second", "third" };
Check out this little blurb on initialization. Why do you want to do it in separate files? You'll have to do externs.
// in .h
extern const char* Title[];
// in .c
const char* Title[] = { "first", "second" };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With