use a text file in an array

Hi Guys,

- i want to use a txt file store in my sketch folder named "tmp.txt"
- i want to include it in my sketch in a array and use it

const int tmp_data [] = { #include "tmp.txt"  };


void setup() {

  Serial.begin(9600);
    while (!Serial);  // wait for serial port to connect. Needed for native USB

  Serial.print("At place 0: ");
  Serial.println (tmp_data [0]);

  Serial.print("At place 7: ");
  Serial.println (tmp_data [7]);

  Serial.print("At place 15: ");
  Serial.print (tmp_data [15]);

} // FIN de setup




void loop() {

} //FIN de loop

The "temp.txt" file is like that , when open with "notepad" : 8,6,4,3,9,7,4,2,1,3,5,4,10,546

This is the compilation error : SKETCH\essai_table_txt\essai_table_txt.ino:25:22: fatal error: tmp.txt: No such file or directory
** #include "tmp.txt"**

The "temp.txt" file is realy in the sketch folder !

Someone to help me ? :wink:

Thanks

You can't include anything that isn't source or definition files (.c .cpp .h).

arduino_new:
You can't include anything that isn't source or definition files (.c .cpp .h).

i have see this topic : How to import data from excel to an arduino sketch - #4 by wg0z - Programming Questions - Arduino Forum

that i think it's was possible ?

From the error message I deduct that the compiler would happily include the *.txt,
but the build process did not copy that file to the build location.

Try renaming the file to tmp.h.

And, while it seems to work, I would put the #include on a separate line.

Whandall:
From the error message I deduct that the compiler would happily include the *.txt,
but the build process did not copy that file to the build location.

Try renaming the file to tmp.h.

YESS its working !!

const int tmp_data [] = {
#include "tmp.h"
};

Whandall:
And, while it seems to work, I would put the #include on a separate line.

How did you write this ?

#include "tmp.h"
const int tmp_data [] = {
???????
};

How did you write this ?

Like you did.

const int tmp_data [] = {
#include "tmp.h"
};

That include statement is on a line by itself.

why Whandall said "I would put the #include on a separate line." ?

superninja:
why Whandall said "I would put the #include on a separate line." ?

Because that is the convention.

ok, i take this. Thanks All