How to name a file using a variable?
hello all! fiddling around sd module, trying figure out how use data logger project. i've ran problem of trying name file after variable, such date. don't have rtc module (yet) set static variable (dt) birthdate (19910401) in yyyymmdd format (was ddmmyyyy leading 0 caused octal constant error). when trying plug in dt.txt or dt".txt" ran errors. had feeling would, tried in case. here code far:
any suggestions appreciated.
during google searching came across sprintf() mentioned in similar posts, cannot find documentation on , not understand how works.
code: [select]
#include <spi.h>
#include <sd.h>
int dt = 19910401;
file myfile;
void setup() {
serial.begin(9600);
while (!serial){}
serial.print("initializing sd card...");
if (!sd.begin(10, 11, 12, 13)){
serial.println("initialization failed");
return;
}
serial.println("initilization done.");
myfile = sd.open(dt.txt, file_write);
myfile.println("will work?");
myfile.close();
}
void loop() {
// put main code here, run repeatedly:
}
any suggestions appreciated.
during google searching came across sprintf() mentioned in similar posts, cannot find documentation on , not understand how works.
was ddmmyyyy leading 0 caused octal constant error).should not, because trick want text


however when trying plug in dt.txt or dt".txt" ran errors.like said, should text

two options, on compiler time
code: [select]
const char filename[] = "19910401.txt"; ///dt terrible name ;)
or @ runtime
code: [select]
unsigned long date = 19910401; //does not fit in (unsigned) int ;)
char filename[13]; //8 char date + 4 (".txt") + 1 null termination
sprintf(filename, "%08lu.txt", date);
but cannot find documentation on , not understand how works.then you're terrible @ searching

Arduino Forum > Using Arduino > Programming Questions > How to name a file using a variable?
arduino
Comments
Post a Comment