#include file with an array?

Hey guys, quick question--

I'm writing some video game code that will have a long list of weapon names stored as strings that I want to select by an index.

For instance, weaponName[0] = "Heavy Machinegun", weaponName[1] = "Gauss Rifle", etc.

I could declare all the contents in the code, but I'm wondering if there's a way to save some real estate by having the array contents in an #included file.

If so, what is the procedure for implementing such a thing?

Thank you very much!

Wes

Hi Sergeant,

Nope, don't put "executable" code like arrays in header files, just definitions and function prototypes.

It won't save space, either. You should consider storing the arrays in flash memory. See the following links:

http://arduino.cc/en/Tutorial/Memory

http://arduino.cc/en/Serial/Print?from=Reference.PrintHex

You can pass flash-memory based strings to Serial.print() by wrapping them with F(). For example : Serial.print(F(“Hello World”))

Pat

file1.ino

#include "myneatarray.c"

void setup() {}
void loop(){}

myneatarray.c (in same directory)

int ary[] = {3, 1, 4, 1, 5, 9};

this should also work: file1.ino

int ary[] = {
#include "myneatarray.c"
};
void setup() {}
void loop(){}

myneatarray.c (in same directory)

3, 1, 4, 1, 5, 9

include just has something run before the compiler insert the one file into the other. It doesn't care about anything else.