C++ pointeur probM

lavoiekeven Messages postés 22 Date d'inscription   Statut Membre Dernière intervention   -  
 Marc -
Bonjour,
je dois traiter des donnes pour un exercise d'ecole, la tache a faire est de parcourir une liste chainée pour supprimer le dossier du professeur vous, mais j'ai un problem a compares les pointeur


VOICI LA FONCTION PROBLÉMATIQUE:
void Dossierprofesseur::supprimer (char * nom,char * prenom)
{
Professeur * Pt_Prof_Courant = Tete;
Professeur * Pt_Prof_Tmp = NULL ;
Cours * Pt_Cours_Tmp = NULL;
Cours * Pt_Cours_Courant = NULL;


do
{

Pt_Prof_Tmp = Pt_Prof_Courant->Suivant;
if((Pt_Prof_Courant->Nom == nom) && (Pt_Prof_Courant->Prenom == prenom))//evalue la premiere case si debut de liste
{
Tete = Pt_Prof_Courant->Suivant;
cout<<Tete->Prenom<<"test";
return;
}

if((Pt_Prof_Tmp->Nom == nom) && (Pt_Prof_Tmp->Prenom == prenom))//evalue la deuxiexe case
{

Pt_Prof_Courant->Suivant = Pt_Prof_Tmp->Suivant; //supprime le prof
delete [] Pt_Prof_Tmp->Nom;
delete [] Pt_Prof_Tmp->Prenom;

Pt_Cours_Courant = Pt_Prof_Tmp->ListeCours;
do //supprime les cours
{
Pt_Cours_Tmp = Pt_Cours_Courant->Suivant;
delete Pt_Cours_Courant;
Pt_Cours_Courant = Pt_Cours_Tmp;
} while (Pt_Cours_Courant->Suivant != NULL);
Pt_Prof_Courant->Suivant = Pt_Prof_Tmp->Suivant;
delete [] Pt_Prof_Courant->Suivant;
return;
}
Pt_Prof_Courant = Pt_Prof_Tmp;
}while (Pt_Prof_Courant->Suivant != NULL);
cout<<"Le nom a suprimer :"<<prenom<<nom;
}

STRUCTURE PROFESSEUR :
struct Professeur {
char * Nom;
char * Prenom;
int Experience;
Cours * ListeCours;
Professeur * Suivant;
};

APPEL DANS LE MAIN:
char * Nom =NULL,* Prenom = NULL;;
char nom[20],prenom[20];
{
operation>> nom;
operation>> prenom;
Nom = new char[20];
strcpy(Nom, nom);
Prenom = new char[20];
strcpy(Prenom, prenom);
liste1.supprimer(Nom , Prenom);
choix=NULL;
break;
}

1 réponse

Marc
 
Bonjour,

Il te suffit d'utiliser la fonction 'strcmp' ;
par exemple :

if( !strcmp(Pt_Prof_Courant->Nom,nom) && !strcmp(Pt_Prof_Courant->Prenom,prenom) )

Extrait du manuel :

SYNOPSIS
#include <string.h>

int strcmp(const char *s1, const char *s2);

int strncmp(const char *s1, const char *s2, size_t n);

DESCRIPTION
The strcmp() function compares the two strings s1 and s2. It returns
an integer less than, equal to, or greater than zero if s1 is found,
respectively, to be less than, to match, or be greater than s2.

The strncmp() function is similar, except it only compares the first
(at most) n characters of s1 and s2.
0