Concatenating char arrays

Hi all,

I have this bit of code:

char directory[] = "/06142012";
char prefix[] = "06042012";
char datafile[] = "06142012/06142012.dat";
char scriptfile[] = "06142012/06142012.p";
char califile[] = "06142012/0614cali.txt";

I'm using char arrays because that's what the SD library needs to write filenames and directories.

However, I'm lazy. I need a new set of files every day. As you can see, the date is included in all the things. But setting up the instruments for new data every day requires changing all these variables. Is there a way I can set one variable with the date and then build all the other char arrays automatically somehow?

sprintf is your friend.

char filename[30]; // leave enough room here.
int day = 20;
int month = 4;
year = 1933;

sprintf(filename,"%d-%d-%d-sensor1.dat",day,month,year);

filename will contain "20-4-1933-sensor1.dat".