sprintf -- strange behaviour

Hello everyone.

I’m building a datalogger for a model rocket. I’m doing the code in sections so what you see here is just testing opening a .csv with a filename that will eventually change for each launch.
I’m using an Arduino nano and a micro SD card with the latest IDE version.

#include <SPI.h>
#include <SdFat.h>

SdFat sd;
SdFile myFile;

const int chipSelect = 10;
int file_count = 7;
char filename[50];

void setup() {
  Serial.begin(9600);
  while (!Serial) {}  // wait for Leonardo
  delay(1000);  // catch Due reset problem

  if (!sd.begin(chipSelect, SPI_FULL_SPEED)) {}

  sprintf(filename, "Launc%03d.csv", file_count);
  Serial.println(filename);
  
  // open the file for write at end like the Native SD library
  if (!myFile.open(filename, O_RDWR | O_CREAT | O_AT_END)) {
    sd.errorHalt("opening csv for write failed");
  }
  // if the file opened okay, write to it:
  Serial.println("Writing to csv...");
  myFile.println("testing 1, 2, 3.");

  myFile.close();  // close the file:
  Serial.println("Done");
}

void loop() {
}

I was having issues whereby sometimes it would open the csv and other times not. I narrowed in on the sprintf function and found something strange.

sprintf(filename, “Launc%03d.csv”, file_count);
This line works fine.

Add an ‘h’ and it doesnt.
sprintf(filename, “Launch%03d.csv”, file_count);

I also tried File%03d.csv and that was fine. After playing around it seems like as long as the preceeding letters to 001.csv are 5 letters or shorter it is fine, 6 doesnt work though. I also tried changing the size of the char array and that had no impact.

This has really confused me, if anyone has any ideas I’d love to hear them. I would like it to open a file called: “Launch001.csv”. Worst case I can just shorten the filename but I would rather understand what is going wrong rather than just blindly accepting it.

Many Thanks

I think sdfat requires 8.3 format. Your results seem to confirm that.