Best Way To Establish String Constant Arrays

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
BeS__284136
Level 3
Level 3
5 sign-ins 10 replies posted 5 replies posted

As part of my stereo preamplifier project, I am attempting to create messages that are stored as constants in an array of chars.

   

 

   

const char Inputs[6][7] =  {"TUNER", "OPTICAL",
                                            "AV", "SERVER", "PHONO", "FRONT"};

   

I need these messages to be stored in a global header file so elements throughout my program can access them. When I declare the above line in a c file, it compiles fine. In a header file, even if I use the extern keyword, my code does not compile.

   

What is the best method to declare a constant array of strings in a header file?

0 Likes
2 Replies
lock attach
Attachments are accessible only for community members.
EvPa_264126
Level 7
Level 7
500 replies posted 250 replies posted 100 likes received

SO?
 

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Usually in a .g file you just declare items. This will not allocate any code, flash or sram.

   

In one of the files you define what has been declared. This ensures that the data is allocated only once.

   

So in the .h file you declare the external array and in your main.c you define as pavloven showed the arrays.

   

 

   

Bob

0 Likes