0
votes

i'm trying to delete a node from an bst in line: ((strcmp((*A)->caracterise.nom , Etud.nom) == 0) && (strcmp((*A)->caracterise.prenom , Etud.prenom) == 0) && ((*A)->caracterise.note == Etud.note))

i get [Error] request for member 'caracterise' in '* A', which is of pointer type 'ABR {aka noud*}' (maybe you meant to use '->' ?)

NOTE: etudiant is student; noud is node; caracterise is student information; nom prenom note are name family-name gpa; fG is left bst; fD is right bst; ABR is BST

struct etudiant
{
char nom[13]; 
char prenom[13];
float note;
};

struct noud
{
etudiant caracterise;
struct noud*fG;
struct noud*fD;
};

typedef struct noud*ABR;

void supprimer(ABR** A, etudiant Etud){
if ((strcmp((*A)->caracterise.nom , Etud.nom) == 0) && (strcmp((*A)->caracterise.prenom , Etud.prenom) == 0) && ((*A)->caracterise.note == Etud.note)) {
    //if ((test(*A, Etud) == 0)&& (*A->caracterise.note == Etud.note)){
    ABR* a;
    a = (ABR*)malloc (sizeof(noud));
    a = (*A)->fD ;
    ABR* b;
    b = (ABR*)malloc (sizeof(noud));
    if ( a != NULL ) {
        if ( a->fG != NULL ) {
            while ( a->fG->fG != NULL ) {
                a = a->fG ;
            }
            b = a->fG ;
            b->fG = (*A)->fG ;
            a->fG = b->fD ;
            b->fD = (*A)->fD;
            a = (*A);
            (*A) = b ;
            free(a);
        }else{
            a->fG = (*A)->fG ;
            free(*A);
            (*A) = a ;
        }
    }else{
        a = *A ;
        (*A) = (*A)->fG ;
        free(a);
    }
}else{
    if ( v.priorite > (*A)->val.priorite ) {
        supprimer(&(*A)->fD, Etud);
    }else{
        supprimer(&(*A)->fG, Etud);
        }
    }
}
1
Thats what you get when you hide a pointer behind a typedef. A is of type noud *** so *A is of type noud ** which you can not access with ->. - Osiris
Unrelated to your error, the assignments a = malloc (sizeof(noud)) directly followed by a = (*A)->fD will lead to a memory leak. - Some programmer dude
This is known as karma, see this. Try to rewrite this program with less complicated data types. Use intuitive variable names. Drop pointer de-referencing in favour of [ ] indexing. - Lundin

1 Answers

1
votes

A is a ABR**, so a struct noud***, so (*A) is a struct noud** not a struct noud* and (*A)->caracterise is wrong (but (**A)->caracterise legal)