toCharArray Issues

Hi all,

Please bear with me, I'm pretty new to Arduino, and my coding skills only go as far as Matlab, but...

Im trying to write some code that will dynamically change the name of a text file that is then going to save to an HD card. So far I have something like:

int trial = 1;
String name = "Evt"; 
String name2 = name += trial;
name2.concat(".txt");
char filename[ name2.length() +1 ];
name2.toCharArray( filename, name2.length() ); 

File dataFile = SD.open(filename, FILE_WRITE);

And eventually trial will count up.

So no matter what I do, I always get files saved that look like EVT1.TX, EVT2.TX, etc etc. The last T never saves. This happens when I use

char filename[ name2.length() ];
char filename[ name2.length() +1 ];
char filename[9]  //should be this for EVT1.TXT
char filename[50]

Nothing I seem to do changes it, even when I allocate enough space. Any thoughts?

char buffer[BUFFER_SIZE];
sprintf (buffer, "EVT%d.txt", trial);

looks to me to be much simpler than using Strings.

name2.toCharArray( filename, name2.length() );

The second argument is the size of the array being written to, NOT the length of the String. The instance already KNOWS its own length.