Salut tout le monde,

J'ai fais un peu le ménage dans ce topic...
On me demande de coder une fonction qui prend une chaine en argument et qui renvoi le code SoundEx de cette chaine.
Voilà ce que j'ai fais jusqu'ici:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
string soundEx(std::string const & str)
{
    char car;
    string str_soundEx = "";
 
    for (unsigned index = 0; index < str.size(); ++index) {
        car = str[index];
 
        if(index == 0){
            if('a' <= car && car <= 'z') {
                char majCar = car - 'a' + 'A';
                str_soundEx += majCar;
            }
            else
                str_soundEx += car;
        }
        else if(car != str[0]) {
            switch(car) {
                case 'a':str_soundEx += ""; break;
                case 'e':str_soundEx += ""; break;
                case 'h':str_soundEx += ""; break;
                case 'i':str_soundEx += ""; break;
                case 'o':str_soundEx += ""; break;
                case 'u':str_soundEx += ""; break;
                case 'w':str_soundEx += ""; break;
                case 'y':str_soundEx += ""; break;
                case 'b':str_soundEx += '1'; break;
                case 'f':str_soundEx += '1'; break;
                case 'p':str_soundEx += '1'; break;
                case 'v':str_soundEx += '1'; break;
                case 'c':str_soundEx += '2'; break;
                case 'g':str_soundEx += '2'; break;
                case 'j':str_soundEx += '2'; break;
                case 'k':str_soundEx += '2'; break;
                case 'q':str_soundEx += '2'; break;
                case 's':str_soundEx += '2'; break;
                case 'x':str_soundEx += '2'; break;
                case 'z':str_soundEx += '2'; break;
                case 'd':str_soundEx += '3'; break;
                case 't':str_soundEx += '3'; break;
                case 'l':str_soundEx += '4'; break;
                case 'm':str_soundEx += '5'; break;
                case 'n':str_soundEx += '5'; break;
                case 'r':str_soundEx += '6'; break;
                default :str_soundEx += '0'; break;
            }
        }
        cout << "index: " << index << endl;
        cout << "TEST: " << str_soundEx[index] << endl;
        if(str_soundEx.size() > 3)
            return str_soundEx;
    }
    while(str_soundEx.size() < 4)
        str_soundEx += '0';
 
 
    return str_soundEx;
}
Il y'a un cas que je n'arrive pas à gérer, c'est celui où un chiffre se repete (exemple : au lieu d'avoir R144 j'dois afficher R14) j'ai beau essayer avec des "str_soundEx[index] ou [--index]" etc... mais rien ne marche

Si quelqu'un pouvait m'aider ou au moins m'aiguiller, ce serait sympa