Bonjour,

J'ai réaliser une interface graphique avec la bibliothèque wxwidgets

Les informations rentrées par l'utilisateur sont stocker dans un type wxstring puis transformer
en char*.


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
 
void TMyFrame::newnoeud(wxCommandEvent& WXUNUSED(event))
{
 
NoeudDialog dialog(NULL,-1,"Créer Noeud",carac);
 
  if ( dialog.ShowModal() == wxID_OK )
         {
 
	   wxString Nom ;
           wxString Conso ;
 
 
            Nom = dialog.GetValue();
            Conso = dialog.GetValue2();
 
 
         cptnoeud= cptnoeud+1 ;      
 
 
          Noeud_Nom[cptnoeud] = Nom.mb_str();
          Noeud_Consommation[cptnoeud] = Conso.mb_str();
 
 
          Noeud_Nom_save[cptnoeud]=Nom.c_str();
          Conso.ToLong(&Noeud_Consommation_save[cptnoeud]);
 
 
 
 
            Noeud1[Nbnoeud]->SetLabel("N: " + Noeud_Nom[cptnoeud]+" / "+ Noeud_Consommation[cptnoeud]);
 
 
            Nbnoeud=Nbnoeud+1;
 
 
         }
}
J'enregistre les données contenue dans les variables Noeud_Nom_save[cptnoeud] et
Noeud_Consomation_save[cptnoeud]dans un fichier txt



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
 
void TMyFrame::OnEnregistrer(wxCommandEvent& WXUNUSED(event))
{
 
 
     FILE* fichier=fopen("table.txt","w");
 
     int i;
 
 
    for (i=1;i<=Nbnoeud;i++)
              {
 
     fprintf(fichier,"Noeud %d : %2d %s \n",i,Noeud_Consommation_save[i],Noeud_Nom_save[i]);
 
 
     }
 
 
 
     fclose(fichier);
 
     wxMessageBox("Programme corectement enregistrer","Enregistrement !");
 
}
Aucune erreur intervient lors de la compilation.

Mais l'enregistrement ne se fait pas comme je le souhaiterais.



Explication :

L'utilisateur rentre à l'aide d'une boite de dialogue le nom d'un Noeud (stocker dans Noeud_Nom_save[])
+ sa consommation(stocker dans Noeud_Consommation_save[]).

Par example :

Paris 147
Marseille 12
Milan 189
Lyon 896

Au final toute les consommations apparaissent corectement mais
seul le dernier nom de Noeud rentrée apparait correctement tous les autre prennent
des chaines de caractères bizarres.



Noeud 1 : 147 N: Lyon / 896
Noeud 2 : 12
Noeud 3 : 189 N: Lyon / 896
Noeud 4 : 896 Lyon


Remarque :

Les noms et la consommations des noeuds sont afficher à l'écran et appaissent corectement :


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
 
Mnoeud=20;
 
for (cpt=0;cpt<Mnoeud;cpt++)
{
Noeud1[cpt] = new wxStaticText(this,-1,"N: ",wxDefaultPosition,
                           wxSize(-1, 20),wxALIGN_LEFT | wxST_NO_AUTORESIZE );
Noeud1[cpt]->SetFont(wxFont(10, wxSWISS , wxNORMAL, wxBOLD, false, "Arial"));
 
}
J'espère être compréhensible.

Yvan Duranton