Fonction pour enlever les caractères accentués d'un tableau de char

J'essaye d'écrire une fonction qui remplace la caractères accentués dans un tableau de char, mais je m'emmêle les pinceaux avec les pointeurs... Un peu d'aide ? ? ?

Voici la fonction

void LookForAccents (char& Text, int TextLength) {
  for (byte i = 0; i < TextLength; i++) {
    if (*(Text+i) > 127) {
      switch (*(Text+i)) {
        case 128:
        case 135:
          *(Text+i) = 'c';
          break;
        case 129:
        case 150 ... 151:
        case 163:
          *(Text+i) = 'u';
          break;

        default:
          break;
      }
    }
  }
}

Je l'ai simplifiée ici mais vous voyez le principe...

Un exemple d'appel :

   LookForAccents (current_weather_description, strlen(current_weather_description));

Et les erreurs de compilation :

Arduino : 1.8.2 (Windows 10), Carte : "LOLIN D32, Default, 80MHz, 921600, None"

In file included from C:\Users\Chuwi\Documents\Arduino\_METEO\Meteo_ESP32_DeepSleep_epaper\Meteo_ESP32_DeepSleep_epaper.ino:2:0:

sketch\Weather.h: In function 'void LookForAccents(char&, int)':

Weather.h:6: error: invalid type argument of unary '*' (have 'int')

     if (*(Text+i) > 127) {

                 ^

Weather.h:7: error: invalid type argument of unary '*' (have 'int')

       switch (*(Text+i)) {

                       ^

Weather.h:10: error: invalid type argument of unary '*' (have 'int')

           *(Text+i) = 'c';

                   ^

Weather.h:15: error: invalid type argument of unary '*' (have 'int')

           *(Text+i) = 'u';

                   ^



In file included from C:\Users\Chuwi\Documents\Arduino\_METEO\Meteo_ESP32_DeepSleep_epaper\Meteo_ESP32_DeepSleep_epaper.ino:2:0:

sketch\Weather.h: In function 'void GetCurrentMeteo()':

Weather.h:129: error: invalid conversion from 'char*' to 'char' [-fpermissive]

     LookForAccents (current_weather_description, strlen(current_weather_description));

                                                                                     ^

In file included from C:\Users\Chuwi\Documents\Arduino\_METEO\Meteo_ESP32_DeepSleep_epaper\Meteo_ESP32_DeepSleep_epaper.ino:2:0:

sketch\Weather.h:4:6: note:   initializing argument 1 of 'void LookForAccents(char&, int)'

 void LookForAccents (char& Text, int TextLength) {

      ^

In file included from C:\Users\Chuwi\Documents\Arduino\_METEO\Meteo_ESP32_DeepSleep_epaper\Meteo_ESP32_DeepSleep_epaper.ino:2:0:

Weather.h:129: error: cannot bind rvalue '(char)((int)(& current_weather_description))' to 'char&'

     LookForAccents (current_weather_description, strlen(current_weather_description));

                                                                                     ^
In file included from C:\Users\Chuwi\Documents\Arduino\_METEO\Meteo_ESP32_DeepSleep_epaper\Meteo_ESP32_DeepSleep_epaper.ino:2:0:

sketch\Weather.h:4:6: note:   initializing argument 1 of 'void LookForAccents(char&, int)'

 void LookForAccents (char& Text, int TextLength) {

      ^

In file included from C:\Users\Chuwi\Documents\Arduino\_METEO\Meteo_ESP32_DeepSleep_epaper\Meteo_ESP32_DeepSleep_epaper.ino:2:0:

Weather.h:225: error: cannot bind rvalue '(char)((int)(& daily_weather_description[i]))' to 'char&'

       LookForAccents (daily_weather_description[i], strlen(daily_weather_description[i]));

                                                  ^


exit status 1
invalid type argument of unary '*' (have 'int')

Je pense que tout est là

Weather.h:129: error: cannot bind rvalue '(char)((int)(& current_weather_description))' to 'char&'

mais je ne comprends pas, ayant beaucoup de mal avec les pointeurs...

j'aurais déclaré come ceci void LookForAccents (char* Text, int TextLength)

Ça compile, mais je conserve mes accents...

Bonjour,

Quand on passe un tableau comme argument il est passé comme référence.
Il suffit donc de faire

void LookForAccents (char Text[], int TextLength) {
  for (byte i = 0; i < TextLength; i++) {
    if (Text[i] > 127) {
      switch (Text[i]) {
        case 128:
        case 135:
          Text[i] = 'c';
          break;
        case 129:
        case 150 ... 151:
        case 163:
          Text[i] = 'u';
          break;

        default:
          break;
      }
    }
  }
}

lesept:
Ça compile, mais je conserve mes accents...

Si c'est un texte qui est inclus dans le source, il est codé en utf8 (dans l'IDE), il faut donc décoder le utf8

Merci Kamill

Ce sont des prévisions météo que je vais chercher sur Internet pour les afficher sur un écran avec la bib Adafruit GFX.

EDIT : il ne reconnait pas les caractères accentués ! Il semble que les codes ASCII ne soient pas ceux que j'ai trouvés. On dirait qu'ils sont codés sur 2 bytes : 195 (0xC3) pour indiquer un caractère spécial puis le code du caractère (160 pour à, 167 pour ç, 168 pour è, 169 pour é...)

Ça vous parle ?

Comme souvent sur le WEB : UTF8
Exemple c2 b0 = °

Merci Henri, je retrouve mon C3 !

J'ai écrit le code et ça fonctionne. Le voici, si ça peut intéresser quelqu'un :

void LookForAccents (char Text[], int TextLength) {
  int i = 0;
  do {
    char c = Text[i];
    if ((int)c == 195) {
      char c2 = Text[i + 1];
      switch ((int)c2) {
        case 160 ... 166:
          Text[i] = 'a';
          break;
        case 167:
          Text[i] = 'c';
          break;
        case 168 ... 171:
          Text[i] = 'e';
          break;
        case 172 ... 175:
          Text[i] = 'i';
          break;
        case 177:
          Text[i] = 'n';
          break;
        case 178 ... 182:
          Text[i] = 'o';
          break;
        case 185 ... 188:
          Text[i] = 'u';
          break;
        case 189 ... 191:
          Text[i] = 'y';
          break;
        case 128 ... 134:
          Text[i] = 'A';
          break;
        case 135:
          Text[i] = 'C';
          break;
        case 136 ... 139:
          Text[i] = 'E';
          break;
        case 140 ... 143:
          Text[i] = 'I';
          break;
        case 146 ... 150:
          Text[i] = 'O';
          break;
        case 153 ... 156:
          Text[i] = 'U';
          break;
        default:
          break;
      }
      for (int j = i + 1; j < TextLength; j++) Text[j] = Text[j + 1];
      TextLength --;
    }
    i++;
  } while (i < TextLength);

}

void setup() {
  Serial.begin(115200);
  char texte[] = "àaâäcçeèé12ëïîioöoôûuUüùÂA34ÄÊ5EË6ÎÏ7ÔÖ8UÛÜ9ÀÇÉÈÊ0Ô";
  Serial.println(texte);
  LookForAccents (texte, strlen(texte));
  Serial.println(texte);
}

void loop() {}

Et voilà la sortie sur la console :

àaâäcçeèé12ëïîioöoôûuUüùÂA34ÄÊ5EË6ÎÏ7ÔÖ8UÛÜ9ÀÇÉÈÊ0Ô
aaaacceee12eiiioooouuUuuAA34AE5EE6II7OO8UUU9ACEEE0O

Je change le titre pour qu'il soit plus explicite.