how to convert float to const char* in sep32

i play esp32-wemos lolin32 for two weeks
i want to store float in to my sdcard, but it just accept const char*
did everybody know how to convert float to const char* in wemos lolin32 :frowning: :frowning:
thank you and sorry about my poor english

.png

hsingyao1010:
did everybody know how to convert float to const char* in wemos lolin32 :frowning: :frowning:

ever hear of 'type casting' or the function 'reinterpret_cast'...?

it just accept const char*

Why do you say that? It does not sound correct. "const" means a value that cannot be updated, so you could not update it to a float or any other value.

You should post your code. Read the forum guide in the sticky post to find out how to use code tags and other useful tips before you post again.

this part is example
void appendFile(fs::FS &fs, const char * path, const char * message ){
Serial.printf("Appending to file: %s\n", path);

File file = fs.open(path, FILE_APPEND);
if(!file){
Serial.println("Failed to open file for appending");
return;
}
if(file.print(message)){
Serial.println("Message appended");
} else {
Serial.println("Append failed");
}
file.close();
}

//////////////////////////////////

void loop(){
digitalWrite(ledr, HIGH); //led開啟
delay(5000); //延遲3秒(=led開啟時間
for (i = 1 ; i <= 7000 ; i++ ) //i=1開始 如果i<5000,i+1
{
V = float(analogRead(pd3));//analogRead讀取(analogInPin)的數值(請看第一行
V = float( V) * float(float(5) / float(1023)) ; //float(float(5)/float(1023)) 數位類比轉換之公式
}
V += V / i ;
digitalWrite(ledr, LOW); //led關閉
Serial.println(V , 4); //this is my float V
delay(100);
appendFile(SD, "/hello.txt", V ); //store code but cant working

how to modify this

appendFile(SD, "/hello.txt", (const char*)&V ); Would be one way.

dtostrf could be another.

my data like this

4.5070
Appending to file: /hello.txt
Message appended
4.5070
Appending to file: /hello.txt
Message appended
4.5070
Appending to file: /hello.txt
Message appended
4.5021
Appending to file: /hello.txt
Message appended
4.5070

data in sdcard

j?@YeS9YeS9YeS9YeGYeS9Ye^aYeS9YeGYe^aYe

i think so close

thank you very much

You didn't say you wanted text.

dtostrf is what you want.

NO :slight_smile:
that text just prompt message
i just store number(4.5070 .....etc)
i try