Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initializing a static const char* array

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"

like image 939
DogDog Avatar asked Sep 28 '10 16:09

DogDog


People also ask

How to initialize a char array with constant values in C?

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.

How do you initialize a string constant in Java?

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";

How do you initialize an array of strings?

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)

How to initialize static const char * const days[]?

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"};


1 Answers

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" };
like image 173
NG. Avatar answered Oct 24 '22 05:10

NG.