C++ pointeur probM
lavoiekeven
Messages postés
22
Date d'inscription
Statut
Membre
Dernière intervention
-
Marc -
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;
}
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;
}
A voir également:
- C++ pointeur probM
- Pointeur souris - Guide
- Curseur Windows 10 : comment bien voir la souris à l'écran - Guide
- Le pointeur de mon pc portable ne marche plus - Guide
- Pointeur laser publicitaire ✓ - Forum Loisirs / Divertissements
- Pointeur souris avec rond de chargement qui clignote sans arrêts ✓ - Forum Windows
1 réponse
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.
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.