Je fais un programme en c++ et j'ai un bug assez bizarre je n,arrive pas à en trouver la cause.. j'aimerais bien que quelqu'un m'aide parce que ça fait plusieurs jours que je tourne en rond à essayer tout et n'importe quoi..
le programme consiste jusqu,a maintenant des structures avec pointeurs dans lequel rentre les données d'un fichier .txt et lequel on affiche après avoir demandé quelque chose à l'usager.. en ce moment tout ce que ça fait c'Est entrer la premier parti des données , puis ça bloque rendu après un tour de la boucle principale , c'Est à dire après "1 professeur"(selon mon type de donnée) j'ai mis en commentaire un gros "bug ici après second tour" pour mettre en évidence l,emplacement exact ou ça bug..et c'est à la création d'une nouvelle case pour la struct et il me semble que ça devrait fonctionner..
voici le code à problème.. je le met en entier au cas où vous voudriez le voir "fonctionner"..merci
#include <iomanip.h>
#include <string.h>
#include <stdlib.h>
#include <iostream.h>
#include <fstream.h>
const int nb_charac_max=80;
struct Cours
{
char *sigle;
Cours *suivant;
};
struct Etudiant
{
char *nom;
Etudiant *suivant;
};
struct Professeur
{
char *nom;
int experience;
Cours *listecours;
Etudiant *listetudiants;
Professeur *suivant;
};
class DossierProfesseur
{
public:
Professeur *tete;
DossierProfesseur(char *FP);
~DossierProfesseur();
void affichage();
};
DossierProfesseur::DossierProfesseur(char *FP)
{
char * t ;
Professeur *profCourant=tete=new Professeur();
cout<< "2";
profCourant->suivant=new Professeur();
cout<< "3";
profCourant = profCourant->suivant;
ifstream lecture(FP,ios::nocreate);
if(lecture.fail()) //condition si l'ouverture envoie une erreur
{
cout<<"Erreur a l'ouverture du fichier"<<endl; //message d'erreur
exit(1); //sortir du programme lors d'une erreur
}
while(!lecture.eof()) //boucle qui lit jusqu'à la fin du fichier
{
cout << "again " << endl;
//******************************************
//*********bug ici au second tour***********
profCourant->nom = new char[25];
cout <<"5";
lecture.getline(profCourant->nom, nb_charac_max);
lecture>>profCourant->experience;
cout << profCourant->experience << "**6";
Cours *coursCourant=profCourant->listecours=new Cours();
coursCourant->suivant=new Cours();
coursCourant=coursCourant->suivant;
Etudiant *etudiantCourant=profCourant->listetudiants=new Etudiant();
etudiantCourant->suivant=new Etudiant();
etudiantCourant=etudiantCourant->suivant;
t = new char [10]; // A remplacer dynamiquement !
while(t[0]!='&' && !lecture.eof())
{
lecture>> t ;
coursCourant->sigle = new char [10];
strcpy (coursCourant->sigle,t);
coursCourant->suivant=new Cours();
coursCourant=coursCourant->suivant;
}
while(t[0]!='&' && !lecture.eof())
{
lecture>> t;
etudiantCourant->nom = new char [20];
strcpy (etudiantCourant->nom,t);
etudiantCourant->suivant=new Etudiant();
etudiantCourant=etudiantCourant->suivant;
}
cout<< "1";
coursCourant->suivant= NULL;
cout<< "1 1/2";
etudiantCourant->suivant= NULL;
profCourant->suivant=new Professeur();
cout<< "3";
profCourant = profCourant->suivant;
cout<< "4";
profCourant->suivant = NULL;
}
}
void DossierProfesseur::affichage()
{
Professeur *profCourant=tete;
profCourant=profCourant->suivant;
while(profCourant->suivant!=NULL)
{
cout << profCourant->nom << endl;
cout << profCourant->experience << endl;
cout << "------------------------------------------------" << endl;
//liste des cours pour ce prof
Cours *coursCourant=profCourant->listecours;
while(coursCourant->suivant!=NULL)
{
coursCourant=coursCourant->suivant;
cout << coursCourant->sigle << endl;
}
profCourant=profCourant->suivant;
}
}
void main()
{
char option_menu[1];
char text_option_menu[nb_charac_max];
cout << "Quel action desirez vous effectuer? (- nom et prenom, *, % nom du cours, $ nom du fichier)";
cin >> option_menu[0];
cin.ignore(2, '[');
cin.get(text_option_menu, nb_charac_max,']');
switch(option_menu[0]){
case '-':cout << "supprimer" << endl << text_option_menu << endl;break;
case '*':cout << "nom plus demander";break;
case '%':cout << "cours";break;
case '$':cout << "sauvegarde";break;
};
DossierProfesseur *dossierProfesseur;
dossierProfesseur= new DossierProfesseur("fp.txt");
dossierProfesseur->affichage();
};