title: Writing to SD card arduino
body: <p>I'm having some troubles with my Arduino. I'm trying to make a dynamic name for my file and transform it to char array like I saw on some post from this website.</p>
  
  <p>Here's how I wrote my function:</p>
  
  <pre><code>void writeSD()
  { 
    DateTime dt = RTC.now();
  
    String temp = "DIVE";
    temp += dt.day();
    temp += dt.month();
    temp += dt.year();
    temp += ".txt";
  
    Serial.println(temp);
  
    char filename[temp.length()+1];
    temp.toCharArray(filename, sizeof(filename));
    myFile = SD.open(filename, FILE_WRITE);  
  
    if (myFile) {
      Serial.print("Writing to txt file...");
      myFile.print(dt.day(), DEC);
      myFile.print('-');
      myFile.print(dt.month(), DEC);
      myFile.print('-');
      myFile.print(dt.year(), DEC);
      myFile.print(' ');
      myFile.print(dt.hour(), DEC);
      myFile.print(':');
      myFile.print(dt.minute(), DEC);
      myFile.print(':');
      myFile.print(dt.second(), DEC);
      myFile.println();
      myFile.close();
      Serial.println("done.");
    } else {
      Serial.println("error opening txt file");
    }
  }
  </code></pre>
  
  <p>I'm only having <code>"error opening txt file"</code> and I don't know why. The name of my file is correct and appears like this when I print it on the console : <code>DIVE652014.TXT</code></p>