string utf8 convert

Hello guys!

Im making a text scroller with led display… And im using the method above to convert the utf8 chars to display the right chars… (thanks to ElToberino - https://github.com/ElToberino/Tobers_Multidisplay)

void utf8AsciiConvert(char* src, char*des)                 
{       int k=0;
       char c;
       for (int i=0; src[i]; i++){
            c = utf8Ascii(src[i]);
            if (c!='\0') //if (c!=0)
            des[k++]=c;
       }
       des[k]='\0';  //des[k]=0;
}


when i convert a simple string, works... But now im saving the string into the eeprom and recovering when the system starts... And every utf8 char return like "⸮" and the convertion is wrong.


//WORK
char msgDisplay[100] = "olá cão";
utf8AsciiConvert(msgDisplay,msgDisplay);  //return olá cão




//DONT WORK

#include <FS.h>
char msgDisplay[100] = "";

String readFile(void) {
 String line = "";  
 File rFile = SPIFFS.open("/log.txt","r");
 Serial.println("Reading file...");
 while(rFile.available()) {
   line = rFile.readStringUntil('\n');

 }
 rFile.close();
 return line;
}

String data = readFile(); //return "olá cão"
strcpy(msgDisplay, data.c_str());
utf8AsciiConvert(msgDisplay,msgDisplay); //return ol co"P" <- strange char

someone could help me?

thanks so much!!

Rafael

UPDATED

I made some serial debugging to see what is converted…printed the char and the ascci number

Message Recovered from eeprom:
olá cão
111 108 195 161 32 99 195 163 111 13 0

convert: o-111 0 0 0 0 0 0 0 0 0 0
into: o-111 0 0 0 0 0 0 0 0 0 0

convert: l-108 0 0 0 0 0 0 0 0 0 0
into: l-108 0 0 0 0 0 0 0 0 0 0

convert: ⸮-195 0 0 0 0 0 0 0 0 0 0
into: -0 0 0 0 0 0 0 0 0 0 0

convert: ⸮-161 0 0 0 0 0 0 0 0 0 0
into: ⸮-225 0 0 0 0 0 0 0 0 0 0

convert:  -32 0 0 0 0 0 0 0 0 0 0
into:  -32 0 0 0 0 0 0 0 0 0 0

convert: c-99 0 0 0 0 0 0 0 0 0 0
into: c-99 0 0 0 0 0 0 0 0 0 0

convert: ⸮-195 0 0 0 0 0 0 0 0 0 0
into: -0 0 0 0 0 0 0 0 0 0 0

convert: ⸮-163 0 0 0 0 0 0 0 0 0 0
into: ⸮-227 0 0 0 0 0 0 0 0 0 0

convert: o-111 0 0 0 0 0 0 0 0 0 0
into: o-111 0 0 0 0 0 0 0 0 0 0

convert: -13 0 0 0 0 0 0 0 0 0 0
into: -13 0 0 0 0 0 0 0 0 0 0

You’re reading the data into a String called “data”, but displaying “msgDisplay”

Please remember to use code tags when posting code

thanks for the advice..i updated the question... The problem is why works on string "typed" and when i recover from eeprom dont works... ;(

TheMemberFormerlyKnownAsAWOL:
You're reading the data into a String called "data", but displaying "msgDisplay"

OP is copying the data from data to msgDisplay before converting it.

OP is not, though, printing data or msgDisplay to prove that the String class handles the utf8 characters correctly.

Thanks all that answered, my problem was solved. There´s an error on the font file that converts the chars… I lookud some on the web and found one that work very well… Noob! lol