Bonjour à tous,
J'ai fait un carnet d'adresse. Le programme tri les contacts par nom et par prénom (s'il y a plusieurs contacts de même nom). Dans celui-ci, il y a une option "Modifier un contact". Mais quand je modifie le nom ou le prénom d'un contact, celui reste à la même place dans le tableau et les contacts ne sont alors plus dans l'ordre alphabétique. Voici le code source de la fonction de modification. J'ai fait uniquement le tri quand le nom est changé car comme ça ne fonctionne pas, ce n'est pas la peine de le faire pour le prénom car je se sera la même chose.

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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Function Menu_changing (Var t: array of personne; qte: Byte):integer;
Var i, j, choix: byte; info: personne;
Begin
 choix:=1;
 gotoxy(35,1);
 WriteLn ('____________________');
 gotoxy(33,4);
 WriteLn ('Modification d''un contact');
 gotoxy(35,6);
 WriteLn ('____________________');
 WriteLn; WriteLn;
 If (qte>0) then
    Begin
       i:=0; choix:=1;
       Write ('Nom:         '); ReadLn (info.nom);
       Write ('Prenom:      '); ReadLn (info.prenom);
       WriteLn;
       clrscr;
       While (info.nom+info.prenom<>t[i].nom+t[i].prenom) AND (i<qte) do i:=i+1;
       If (info.nom+info.prenom=t[i].nom+t[i].prenom) AND (i<qte) then
          Begin
             While (choix<>0) do
                Begin
                  gotoxy(35,1);
                  WriteLn ('____________________');
                  gotoxy(33,4);
                  WriteLn ('Modification d''un contact');
                  gotoxy(35,6);
                  WriteLn ('____________________');
                  WriteLn; WriteLn;
                  WriteLn('',t[i].nom,' ',t[i].prenom,', rue ',t[i].rue,' ',t[i].numero,', ',t[i].cp,' ',t[i].localite,'');
                  WriteLn;
                  WriteLn (' Modification');
                  WriteLn (' ------------');
                  WriteLn;
                  WriteLn ('  1) Nom');
                  WriteLn ('  2) Prenom');
                  WriteLn ('  3) Rue');
                  WriteLn ('  4) Numero');
                  WriteLn ('  5) Code postal');
                  WriteLn ('  6) Localite');
                  WriteLn ('  0) Retour');
                  WriteLn;
                  Write ('Que voulez vous faire? '); ReadLn (choix);
                  clrscr;
                  gotoxy(35,1);
                  WriteLn ('____________________');
                  gotoxy(33,4);
                  WriteLn ('Modification d''un contact');
                  gotoxy(35,6);
                  WriteLn ('____________________');
                  WriteLn; WriteLn;
                  Case choix of
                    1: Begin
                          Write ('Nom:    '); ReadLn (info.nom);
                          i:=0;
                          While (info.nom>t[i].nom) AND (i<qte) do i:=i+1;
                          j:=qte;
                          While (j>i) do
                             Begin
                                t[j]:=t[j-1];
                                j:=j-1;
                             End;
                          t[i].nom:=info.nom;
                       End;
                    2: Begin
                          Write ('Prenom:  '); ReadLn (info.prenom);
                          t[i].prenom:=info.prenom;
                       End;
                    3: Begin
                          Write ('Rue:  '); ReadLn (info.rue);
                          t[i].rue:=info.rue;
                       End;
                    4: Begin
                          Write ('Numero:  '); ReadLn (info.numero);
                          t[i].numero:=info.numero;
                       End;
                    5: Begin
                          Write ('Code postal:  '); ReadLn (info.cp);
                          t[i].cp:=info.cp;
                       End;
                    6: Begin
                          Write ('Localite:  '); ReadLn (info.localite);
                          t[i].localite:=info.localite;
                       End;
                    Else If (choix<>0) then
                       Begin
                          clrscr;
                          gotoxy(35,1);
                          WriteLn ('____________________');
                          gotoxy(42,4);
                          WriteLn ('Erreur  ');
                          gotoxy(35,6);
                          WriteLn ('____________________');
                          WriteLn; WriteLn;
                          WriteLn ('Entrez un numero valide');
                          WriteLn;
                          WriteLn ('Pressez ENTER pour revenir au menu'); ReadLn;
                          clrscr;
                       End;
                    End;
                End;
          End
       Else
          Begin
             gotoxy(35,1);
             WriteLn ('____________________');
             gotoxy(33,4);
             WriteLn ('Modification d''un contact');
             gotoxy(35,6);
             WriteLn ('____________________');
             WriteLn; WriteLn;
             WriteLn ('Ce contact n''existe pas');
             WriteLn;
             WriteLn ('Pressez ENTER pour revenir au menu principal'); ReadLn;
             clrscr;
          End;
    End
 Else
    Begin
       WriteLn ('La liste de contact est vide');
       WriteLn;
       WriteLn ('Pressez ENTER pour revenir au menu principal'); ReadLn;
       clrscr;
    End;
End;
Merci d'avance pour votre aide.