Conversion from 'const char*' to 'char'

Hello i have problem t

To understand this problem, i want to save in a variable the date that i get from the function printLocalTime to use it after to create a file with the date on a SD card, but i don't know how i can do this on the following line :

char date= ('const char(&timeinfo, "%F")');

Here under i put the more complete code for better understanding thanks :

void printLocalTime(){
                            struct tm timeinfo;
                            if(!getLocalTime(&timeinfo)){
                            Serial.println("Failed to obtain time");
                            return;
                            }
  Serial.print("Day of week: ");
  Serial.println(&timeinfo, "%A");
  Serial.print("Month: ");
  Serial.println(&timeinfo, "%m");
  Serial.print("Day of Month: ");
  Serial.println(&timeinfo, "%d");
  Serial.print("Year: ");
  Serial.println(&timeinfo, "%Y");
  Serial.print("Hour: ");
  Serial.println(&timeinfo, "%H");
  Serial.print("Minute: ");
  Serial.println(&timeinfo, "%M");
  Serial.print("Second: ");
  Serial.println(&timeinfo, "%S");
  Serial.print ("Il est exactement : ");
  Serial.print(&timeinfo, "%X");
  Serial.println (" Heures");
  Serial.print("Nous sommes en : ");
  Serial.println(&timeinfo, "%F");                            
  char date= ('const char(&timeinfo, "%F")'); // OBJECTIF / Obtenir la date pour Ă©criture sur carte SD
  Serial.print ('date');                         
                            }
void loop(){
printLocalTime();//Appel de la fonction printLocalTime  
appendFile(SD, "/hello.txt", "World!\n");
delay (1000);
appendFile(SD, "/hello.txt", "HH\n");
delay (1000);
appendFile(SD, "/hello.txt", "BB ");
delay (1000);
appendFile(SD, "/hellolol.txt", "BB ");
Serial.print (date); 

Yours, or ours?

Can you explain this, please?

Serial.println(&timeinfo, "%A");

Please remember to use code tags when posting code.

Read the forum guidelines to see how to properly post code.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

The code is not complete. Post the complete code or a minimal verifiable code that exhibits the fault.

Sorry i am french and i don' undersatnd your question Yours, or ours... what are you talking about ?
i have tried tu put the code between < > but i think i miss something sorry

There is a francophone forum.

What I meant was "Was the code for our (other forum users) better understanding, or for your better understanding? Because it didn't really help"

Ok i just learn the ctrl-t :wink:
ok the complete code

//Variable communication carte SD
#include "FS.h"
#include "SD.h"
//END

//Variable gestion WIFI, Date et Heure
#include <WiFi.h>
#include "time.h"
const char* ssid     = "XXXXX";
const char* password = "XXXXXX";
const char* ntpServer = "pool.ntp.org";
const long  gmtOffset_sec = 0;
const int   daylightOffset_sec = 3600;
String date;
//END

void removeDir(fs::FS &fs, const char * path) {
  Serial.printf("Removing Dir: %s\n", path);
  if (fs.rmdir(path)) {
    Serial.println("Dir removed");
  } else {
    Serial.println("rmdir failed");
  }
}

void appendFile(fs::FS &fs, const char * path, const char * message) {
  Serial.printf("Tentative ajout au fichier: %s\n", path);

  File file = fs.open(path, FILE_APPEND);
  if (!file) {
    Serial.println("Echec ouverture fichier pour ajout");
    return;
  }
  if (file.print(message)) {
    Serial.println("Ecriture fichier reussi");
  } else {
    Serial.println("Echec Ă©criture fichier");
  }
  file.close();
}

void deleteFile(fs::FS &fs, const char * path) {
  Serial.printf("Deleting file: %s\n", path);
  if (fs.remove(path)) {
    Serial.println("File deleted");
  } else {
    Serial.println("Delete failed");
  }
}

void setup() {
  Serial.begin(9600);
  // Connect to Wi-Fi
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Tentative de connexion...");
  }
  Serial.println("");
  Serial.println("WiFi connected.");

  // Init and get the time
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
  printLocalTime();

  //disconnect WiFi as it's no longer needed
  WiFi.disconnect(true);
  WiFi.mode(WIFI_OFF);

  if (!SD.begin(5)) {
    Serial.println("Card Mount Failed");
    return;
  }
  uint8_t cardType = SD.cardType();

  if (cardType == CARD_NONE) {
    Serial.println("No SD card attached");
    return;
  }

  Serial.print("SD Card Type: ");
  if (cardType == CARD_MMC) {
    Serial.println("MMC");
  } else if (cardType == CARD_SD) {
    Serial.println("SDSC");
  } else if (cardType == CARD_SDHC) {
    Serial.println("SDHC");
  } else {
    Serial.println("UNKNOWN");
  }

  uint64_t cardSize = SD.cardSize() / (1024 * 1024);
  Serial.printf("SD Card Size: %lluMB\n", cardSize);

}
void printLocalTime() {
  struct tm timeinfo;
  if (!getLocalTime(&timeinfo)) {
    Serial.println("Failed to obtain time");
    return;
  }
  Serial.print("Day of week: ");
  Serial.println(&timeinfo, "%A");
  Serial.print("Month: ");
  Serial.println(&timeinfo, "%m");
  Serial.print("Day of Month: ");
  Serial.println(&timeinfo, "%d");
  Serial.print("Year: ");
  Serial.println(&timeinfo, "%Y");
  Serial.print("Hour: ");
  Serial.println(&timeinfo, "%H");
  Serial.print("Minute: ");
  Serial.println(&timeinfo, "%M");
  Serial.print("Second: ");
  Serial.println(&timeinfo, "%S");
  Serial.print ("Il est exactement : ");
  Serial.print(&timeinfo, "%X");
  Serial.println (" Heures");
  Serial.print("Nous sommes en : ");
  Serial.println(&timeinfo, "%F");
  String date = (&timeinfo, "%F"); // OBJECTIF / Obtenir la date pour Ă©criture sur carte SD
  Serial.print ("%F");
}
void loop() {
  printLocalTime();//Appel de la fonction printLocalTime
  appendFile(SD, "/hello.txt", "World!\n");
  delay (1000);
  appendFile(SD, "/hello.txt", "HH\n");
  delay (1000);
  appendFile(SD, "/hello.txt", "BB ");
  delay (1000);
  appendFile(SD, "/hellolol.txt", "BB ");
  Serial.print ('date');


  delay (1000);

}
1 Like

How to use code tags (</>).

Please can you explain what this is?

Please remember to use code tags when posting code.

Ha ok i understand now this is for our (other forum users) to help me on this matter. Thanks

What Arduino board are you using?

Are you sure that you want to broadcast your SSID and password to the world?

Hi thanks i just understand now how to post it proprely.
I print on serial port the day of the week with %A, this is coming from library time.h with a ntp server

Ho no !

This is ESP32 and thanks i modify my code to hide SSID and pass

You should answer the question posed by @ TheMemberFormerlyKnownAsAWOL.

Try this change:

Ok but this is working this, my problem is to pass the value to use it latter

Look

char date= ('const char(&timeinfo, "%F")');

Is just silly - the single quotes make no sense.

Can you please just answer my earlier question?

what is "this"?

Sorry i have problem to follow i answer allready no ?

No, you can't explain it?