From fdefda76d576ca4755878a22eedbc1b95526c012 Mon Sep 17 00:00:00 2001 From: DUVAL Date: Sun, 14 Jun 2015 14:15:11 -0700 Subject: [PATCH] commit final --- README.md | 21 +++++++++++++++++++++ fin.cbp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ fonction .c | 402 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fonction.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.c | 151 ------------------------------------------------------------------------------------------------------------------------------------------------------- programmecomplet.c | 541 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rapport_cuadros_zhang_programmationavancee.pdf | Bin 0 -> 342118 bytes 7 files changed, 1078 insertions(+), 151 deletions(-) create mode 100755 README.md create mode 100755 fin.cbp create mode 100755 fonction .c create mode 100755 fonction.h delete mode 100644 main.c create mode 100755 programmecomplet.c create mode 100755 rapport_cuadros_zhang_programmationavancee.pdf diff --git a/README.md b/README.md new file mode 100755 index 0000000..8080c22 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +Choix de l'utilisateur: + +appuyer sur 1 : affiche les réalisateurs + +appuyer sur 2 : cherche un réalisateur + + le programme demande son nom et son prénom + +appuyer sur 3: affiche le réalisateur + +appuyer sur 4 : efface le réalisateur + +appuyer sur 5 : ajoute un film au réalisateur + +appuyer sur 6 : efface un film au réalisateur + +appuyer sur 7 : ajoute un réalisateur + +appuyer sur 8 : quitter le programme + +Pour utiliser un autre fichier que "very_small_example.list", remplacer le fichier utilisé par celui désiré dans la fonction "void init" localisée dans le fichier "fonction.c". \ No newline at end of file diff --git a/fin.cbp b/fin.cbp new file mode 100755 index 0000000..1346ff6 --- /dev/null +++ b/fin.cbp @@ -0,0 +1,48 @@ + + + + + + diff --git a/fonction .c b/fonction .c new file mode 100755 index 0000000..1037c35 --- /dev/null +++ b/fonction .c @@ -0,0 +1,402 @@ +#include "fonction.h" + +/**Hash functions**/ + +int hash(char *word) +{ + int i = 0; + int nombreHache = 0; + + + for (i = 0 ; word[i] != '\0' ; i++) + { + + nombreHache += word[i]; + + } + + return nombreHache %= TABLE_SIZE; +} +// initialisation du tableau, chaque element dans le tableau est un pointeur de réalisateur + +void initTable(tableReal table) +{ + int e; + for(e = 0;enom,nom) != 0 && strcmp(pt->prenom,prenom) != 0) ) + { + if(pt == NULL) + { + printf("%s %s ne fait pas parti de liste \n",nom,prenom); + break; + } + pt = pt->suivant; + if(strcmp(pt->nom,nom) == 0 && strcmp(pt->prenom,prenom) == 0) + printf("%s %s fait parti de liste \n",nom,prenom); + } + + return pt; +} + +// permet de copier une partie du chaîne dans une autre. + +int readPartOfLine(int a,int b,char line[LINE_MAX],char part[LINE_MAX]) +{ + int debut = a; + int endAv = b; + int av = 0; + while(debut < endAv) + { + part[av] = line[debut]; + debut++; + av++; + } + part[av] = '\0'; + return debut; + +} + +//repérer la position de la fin de chaîne de caractére +int findEnd(char line[LINE_MAX]) +{ + int av = 0; + while(line[av] != '\n') + av++; + return av; +} + +//permet de lire la chaîne de caractére qui correspond à une oeuvre + +void readElement(char element[LINE_MAX],ptoeuvres film) +{ + + int begin = 0; + if(element[0] == '\t') + begin = 2; + int Pbegin = strpbrk(element,"(") - element; + int Pend =strpbrk(element,")") - element; + int end = findEnd(element); + + readPartOfLine(begin,Pbegin,element,film->title); + + readPartOfLine(Pbegin+1,Pend,element,film->annee); + + readPartOfLine(Pend+1,end,element,film->commentaire); + + + +} + +// initialisation des oeuvres + +void initOeuvre(ptoeuvres oe) +{ + + + int e; + for(e = 0;eannee[e] = malloc(sizeof(char)); + oe->commentaire[e] = malloc(sizeof(char)); + oe->title[e] = malloc(sizeof(char)); + } + oe->suivant = NULL; + + +} +// Permet de lire le fichier contenant la liste des réalisateurs +//repere les réalisateurs par l'existence d'une virgule dans la ligne en cours de lecture + +void readFile(FILE *file, tableReal database) +{ + + int actualReal = 0; + int virgule = 0; + int tab = 0; + int end = 0; + int av = 0; + + char line[LINE_MAX]; + char element[LINE_MAX]; + char nom[LINE_MAX]; + char prenom[LINE_MAX]; + + char *ret; + + Oeuvres initOe; + ptoeuvres ptInitOe = NULL; + + + while(av == 0) + { + + if(fgets(line,LINE_MAX,file) != NULL) + { + + + ret = strpbrk(line,","); + if(ret != NULL) + { + virgule = ret - line; + tab = strpbrk(line,"\t") - line; + end = findEnd(line); + readPartOfLine(0,virgule,line,nom); + readPartOfLine(virgule+1,tab,line,prenom); + + int actualReal = hashNum(nom,prenom); + + database[actualReal] = malloc(sizeof(Realisateur)); + readPartOfLine(0,virgule,line,database[actualReal]->nom); + readPartOfLine(virgule+1,tab,line,database[actualReal]->prenom); + + + database[actualReal]->filmographie = malloc(sizeof(Oeuvres)); + ptInitOe = database[actualReal]->filmographie; + + initOeuvre(ptInitOe); + readPartOfLine(tab+1,end,line,element); + readElement(element,ptInitOe); + + + } + else if(strcmp(line,"\n") != 0) + { + + ptInitOe->suivant = malloc(sizeof(Oeuvres)); + ptInitOe = ptInitOe->suivant; + initOeuvre(ptInitOe); + readElement(line,ptInitOe); + } + } + else + av = 1; + + + + } + +} + +// afficher un film + +void afficherFilm(ptoeuvres oe) +{ + printf("titre : %s, annee : %s, commentaire : %s \n",oe->title,oe->annee,oe->commentaire); + +} + +//afficher tous les realisateurs + +void afficherTable(tableReal table) +{ + int e; + ptoeuvres oe; + for(e=0;efilmographie; + printf("nom : %s, prenom : %s \n",table[e]->nom,table[e]->prenom); + while(oe != NULL) + { + afficherFilm(oe); + oe = oe->suivant; + + } + + + } + + } +} + +// Permet d'afficher le réalisateur voulu ainsi que sa filmographie + +void afficherReal(tableReal table,char nom[LINE_MAX],char prenom[LINE_MAX]) +{ + ptrealisateur pt = findReal(table,nom,prenom); + ptoeuvres ptOe = 0; + if(pt != NULL) + { + ptOe = pt->filmographie; + while(ptOe != NULL) + { + afficherFilm(ptOe); + ptOe = ptOe->suivant; + } + + } + + + +} + +// on ajouter un realisateur dans le tableau + +void addReal(tableReal table,char nom[LINE_MAX],char prenom[LINE_MAX]) +{ + if(findReal(table,nom,prenom) == NULL) + { + + printf("ajout en court \n",nom,prenom); + int actualReal = hashNum(nom,prenom); + if(table[actualReal] == NULL) + { + + table[actualReal] = malloc(sizeof(Realisateur)); + memcpy(table[actualReal]->nom,nom,strlen(nom)+1); + memcpy(table[actualReal]->prenom,prenom,strlen(prenom)+1); + table[actualReal]->suivant = NULL; + } + else{ + ptrealisateur pt = table[actualReal]->suivant; + while(pt != NULL) + pt = pt->suivant; + pt = malloc(sizeof(Realisateur)); + memcpy(pt->nom,nom,strlen(nom)+1); + memcpy(pt->prenom,prenom,strlen(prenom)+1); + pt->suivant = NULL; + + + } + + + } + + +} + +// ajouter un film d'un realisateur donné + +void addFilm(tableReal table,char nom[LINE_MAX],char prenom[LINE_MAX] ) +{ + ptrealisateur pt = findReal(table,nom,prenom); + ptoeuvres ptOe = 0; + ptOe = pt->filmographie; + int X = 0; + char anne[LINE_MAX]; + char tittle[LINE_MAX]; + char commentaire[LINE_MAX]; +if(ptOe != NULL) +{ + while(ptOe->suivant != NULL) + { + ptOe = ptOe->suivant; + } +} +else X = 1; + + ptoeuvres newOe = malloc(sizeof(Oeuvres)); + initOeuvre(newOe); + printf("ajouter un film : \ntitre : "); + scanf("%s",&tittle); + printf("annee : "); + scanf("%s",&anne); + printf("commentaire : "); + scanf("%s",&commentaire); + memcpy(newOe->commentaire,commentaire,strlen(commentaire)+1); + memcpy(newOe->title,tittle,strlen(tittle)+1); + memcpy(newOe->annee,anne,strlen(anne)+1); +if(X == 0) + ptOe->suivant = newOe; +else + pt->filmographie = newOe; +} + +int eraseFilm(ptrealisateur real,char title[LINE_MAX]) +{ + ptoeuvres previousOe = real->filmographie; + ptoeuvres nextOe = real->filmographie->suivant; + if(previousOe == NULL) + return 1; + if(nextOe == NULL) + { + if(strcmp(previousOe->title,title) == 0) + { + real->filmographie = NULL; + } + return 1; + } + + +if(nextOe != NULL) +{ + + + while(strcmp(nextOe->title,title) != 0 && (previousOe != NULL && nextOe != nextOe)) + { + previousOe = nextOe; + nextOe = nextOe->suivant; + if(nextOe == NULL) + return 1; + } + previousOe->suivant = nextOe->suivant; + free(nextOe); +} +else +{ + if(strcmp(nextOe->title,title) == 0) + { + free(nextOe); + previousOe->suivant = NULL; + return 1; + } + else if(strcmp(previousOe->title,title) == 0) + { + real->filmographie = nextOe; + free(previousOe); + return 1; + } + + +} + printf("%s n'existe pas \n",title); + + + return 0; + +} + +// supprimer un film d'un réalisateur donné + +void eraseReal(tableReal table,char nom[LINE_MAX],char prenom[LINE_MAX]) +{ + ptrealisateur pt = findReal(table,nom,prenom); + ptoeuvres ptOe = pt->filmographie->suivant; + if(pt != NULL) + { + printf("effacement en court \n"); + while(pt->filmographie != NULL) + { + pt->filmographie = ptOe->suivant; + ptOe = ptOe->suivant; + } + table[hashNum(nom,prenom)] = NULL; + free(ptOe); + free(pt); + } + +} diff --git a/fonction.h b/fonction.h new file mode 100755 index 0000000..dfcb6e0 --- /dev/null +++ b/fonction.h @@ -0,0 +1,66 @@ +#ifndef FONCTION_H_INCLUDED +#define FONCTION_H_INCLUDED +#define TABLE_SIZE 100 +#define LINE_MAX 1000 +#include +#include +#include + + + typedef struct Oeuvres Oeuvres; + struct Oeuvres + { + char title[LINE_MAX]; + char annee[LINE_MAX]; + char commentaire[LINE_MAX]; + Oeuvres *suivant; + + }; + + + typedef Oeuvres *ptoeuvres; + + + typedef struct Realisateur Realisateur; + struct Realisateur + { + char nom[LINE_MAX]; + char prenom[LINE_MAX]; + ptoeuvres filmographie; + Realisateur *suivant; + }; + + typedef Realisateur *ptrealisateur; + typedef ptrealisateur tableReal[TABLE_SIZE]; + + + int hash(char *word); + void initTable(tableReal table); + int hashNum(char nom[LINE_MAX],char prenom[LINE_MAX]); + + + int findEnd(char line[LINE_MAX]); + + void initOeuvre(ptoeuvres oe); + + int readPartOfLine(int a,int b,char line[LINE_MAX],char part[LINE_MAX]); + void readElement(char element[LINE_MAX],ptoeuvres film); + void readFile(FILE *file, tableReal database); + + ptrealisateur findReal(tableReal table,char nom[LINE_MAX],char prenom[LINE_MAX]); + + void afficherFilm(ptoeuvres oe); + void afficherTable(tableReal table); + void afficherReal(tableReal table,char nom[LINE_MAX],char prenom[LINE_MAX]); + + void addReal(tableReal table,char nom[LINE_MAX],char prenom[LINE_MAX]); + void addFilm(tableReal table,char nom[LINE_MAX],char prenom[LINE_MAX] ); + + int eraseFilm(ptrealisateur real,char title[LINE_MAX]); + void eraseReal(tableReal table,char nom[LINE_MAX],char prenom[LINE_MAX]); + + + + + +#endif // FONCTION_H_INCLUDED diff --git a/main.c b/main.c deleted file mode 100644 index e319fa5..0000000 --- a/main.c +++ /dev/null @@ -1,151 +0,0 @@ -#include "fonction.h" - -//explication de l'utilisation du menu - -void commande() -{ - printf("que voulez vous faire ? \n1 = afficher les realisteurs\n2 = chercher et selectionner un realisteur\n3 = afficher le realisateur selectionner\n4 = effacer le realisateur selectionner\n5 = ajouter un film au realisateur selectionner\n6 = effacer un film au realisateur selectioner\n7 = ajouter un realisateur\n8 = quitter \n"); -} - -// Menu du programme - -void menu(tableReal table) -{ - int QUITTER = 0; - int choix = 0; - char nom[LINE_MAX]; - char prenom[LINE_MAX]; - char nomNew[LINE_MAX]; - char prenomNew[LINE_MAX]; - char titre[LINE_MAX]; - ptrealisateur pt = NULL; - commande(); - - while(QUITTER==0) - { - while(choix == 0) - { - scanf("%d",&choix); - if(choix > 8 || choix < 0) - choix = 0; - system("cls"); - } - switch(choix) - { - - case 1: // afficher un realisateur - { - commande(); - afficherTable(table); - choix = 0; - break; - } - case 2: // chercher un realisateur - { - commande(); - printf("chercher, nom : "); - scanf("%s",&nom); - printf("prenom : "); - scanf("%s",&prenom); - pt = findReal(table,nom,prenom); - choix = 0; - break; - } - case 3: //afficher un realisteur selectionne - { - commande(); - if(pt != NULL) - afficherReal(table,pt->nom,pt->prenom); - else - printf("pas de realisateur selectionner !"); - - choix = 0; - break; - } - case 4: // supprimer un realisateur selectionne - { - commande(); - if(pt != NULL) - eraseReal(table,pt->nom,pt->prenom); - else - printf("pas de realisateur selectionner !"); - - choix = 0; - break; - } - - case 5: // ajouter un film dans le realisateur selectionne - { - commande(); - if(pt != NULL) - addFilm(table,pt->nom,pt->prenom); - else - printf("pas de realisateur selectionner !"); - - choix = 0; - break; - } - case 6: //supprimer un film dans le realisateur selectionne - { - commande(); - if(pt != NULL) - { - printf("nom du film à effacer :"); - scanf("%s",titre); - eraseFilm(pt,titre); - } - else - printf("pas de realisateur selectionner !"); - - choix = 0; - break; - } - case 7: // ajouter un realisateur - { - commande(); - printf("ajouter : nom : "); - scanf("%s",&nomNew); - printf("prenom : "); - scanf("%s",&prenomNew); - addReal(table,nomNew,prenomNew); - - choix = 0; - break; - } - case 8: // quitter - { - printf("bye bitches !"); - QUITTER = 1; - break; - } - - - } - - - } - - -} - -// Initialisation de tous les paramètres - -void init() -{ - - tableReal table; - initTable(table); - FILE* fichier = NULL; - fichier = fopen("very_small_example.list", "r+"); - readFile(fichier,table); - fclose(fichier); - - menu(table); - -} -int main() -{ - - init(); - return 0; -} diff --git a/programmecomplet.c b/programmecomplet.c new file mode 100755 index 0000000..5f80d5f --- /dev/null +++ b/programmecomplet.c @@ -0,0 +1,541 @@ +#include +#include +#define LINE_MAX 1000 +#define TABLE_SIZE 100 +#include + + +int hash(char *word) +{ + int i = 0; + int nombreHache = 0; + + + for (i = 0 ; word[i] != '\0' ; i++) + { + + nombreHache += word[i]; + + } + + return nombreHache %= TABLE_SIZE; +} + +typedef struct Oeuvres Oeuvres; +struct Oeuvres +{ + char title[LINE_MAX]; + char annee[LINE_MAX]; + char commentaire[LINE_MAX]; + Oeuvres *suivant; + +}; + + +typedef Oeuvres *ptoeuvres; + + +typedef struct Realisateur Realisateur; +struct Realisateur +{ + char nom[LINE_MAX]; + char prenom[LINE_MAX]; + ptoeuvres filmographie; + Realisateur *suivant; +}; + +typedef Realisateur *ptrealisateur; +typedef ptrealisateur tableReal[TABLE_SIZE]; + + + +void initTable(tableReal table) +{ + int e; + for(e = 0;enom,nom) != 0 && strcmp(pt->prenom,prenom) != 0) ) + { + if(pt == NULL) + { + printf("%s %s ne fait pas parti de liste \n",nom,prenom); + break; + } + pt = pt->suivant; + if(strcmp(pt->nom,nom) == 0 && strcmp(pt->prenom,prenom) == 0) + printf("%s %s fait parti de liste \n",nom,prenom); + } + + return pt; +} +int readPartOfLine(int a,int b,char line[LINE_MAX],char part[LINE_MAX]) +{ + int debut = a; + int endAv = b; + int av = 0; + while(debut < endAv) + { + part[av] = line[debut]; + debut++; + av++; + } + part[av] = '\0'; + return debut; + +} +int findEnd(char line[LINE_MAX]) +{ + int av = 0; + while(line[av] != '\n') + av++; + return av; +} +void readElement(char element[LINE_MAX],ptoeuvres film) +{ + + int begin = 0; + if(element[0] == '\t') + begin = 2; + int Pbegin = strpbrk(element,"(") - element; + int Pend =strpbrk(element,")") - element; + int end = findEnd(element); + + readPartOfLine(begin,Pbegin,element,film->title); + + readPartOfLine(Pbegin+1,Pend,element,film->annee); + + readPartOfLine(Pend+1,end,element,film->commentaire); + + + +} +void initOeuvre(ptoeuvres oe) +{ + + + int e; + for(e = 0;eannee[e] = malloc(sizeof(char)); + oe->commentaire[e] = malloc(sizeof(char)); + oe->title[e] = malloc(sizeof(char)); + } + oe->suivant = NULL; + + +} + +void readFile(FILE *file, tableReal database) +{ + + int actualReal = 0; + int virgule = 0; + int tab = 0; + int end = 0; + int av = 0; + + char line[LINE_MAX]; + char element[LINE_MAX]; + char nom[LINE_MAX]; + char prenom[LINE_MAX]; + + char *ret; + + Oeuvres initOe; + ptoeuvres ptInitOe = NULL; + + + while(av == 0) + { + + if(fgets(line,LINE_MAX,file) != NULL) + { + + + ret = strpbrk(line,","); + if(ret != NULL) + { + virgule = ret - line; + tab = strpbrk(line,"\t") - line; + end = findEnd(line); + readPartOfLine(0,virgule,line,nom); + readPartOfLine(virgule+1,tab,line,prenom); + + int actualReal = hashNum(nom,prenom); + + database[actualReal] = malloc(sizeof(Realisateur)); + readPartOfLine(0,virgule,line,database[actualReal]->nom); + readPartOfLine(virgule+1,tab,line,database[actualReal]->prenom); + + + database[actualReal]->filmographie = malloc(sizeof(Oeuvres)); + ptInitOe = database[actualReal]->filmographie; + + initOeuvre(ptInitOe); + readPartOfLine(tab+1,end,line,element); + readElement(element,ptInitOe); + + + } + else if(strcmp(line,"\n") != 0) + { + + ptInitOe->suivant = malloc(sizeof(Oeuvres)); + ptInitOe = ptInitOe->suivant; + initOeuvre(ptInitOe); + readElement(line,ptInitOe); + } + } + else + av = 1; + + + + } + +} +void afficherFilm(ptoeuvres oe) +{ + printf("titre : %s, annee : %s, commentaire : %s \n",oe->title,oe->annee,oe->commentaire); + +} +void afficherTable(tableReal table) +{ + int e; + ptoeuvres oe; + for(e=0;efilmographie; + printf("nom : %s, prenom : %s \n",table[e]->nom,table[e]->prenom); + while(oe != NULL) + { + afficherFilm(oe); + oe = oe->suivant; + + } + + + } + + } +} +void afficherReal(tableReal table,char nom[LINE_MAX],char prenom[LINE_MAX]) +{ + ptrealisateur pt = findReal(table,nom,prenom); + ptoeuvres ptOe = 0; + if(pt != NULL) + { + ptOe = pt->filmographie; + while(ptOe != NULL) + { + afficherFilm(ptOe); + ptOe = ptOe->suivant; + } + + } + + + +} +void addReal(tableReal table,char nom[LINE_MAX],char prenom[LINE_MAX]) +{ + if(findReal(table,nom,prenom) == NULL) + { + + printf("ajout en court \n",nom,prenom); + int actualReal = hashNum(nom,prenom); + if(table[actualReal] == NULL) + { + + table[actualReal] = malloc(sizeof(Realisateur)); + memcpy(table[actualReal]->nom,nom,strlen(nom)+1); + memcpy(table[actualReal]->prenom,prenom,strlen(prenom)+1); + table[actualReal]->suivant = NULL; + } + else{ + ptrealisateur pt = table[actualReal]->suivant; + while(pt != NULL) + pt = pt->suivant; + pt = malloc(sizeof(Realisateur)); + memcpy(pt->nom,nom,strlen(nom)+1); + memcpy(pt->prenom,prenom,strlen(prenom)+1); + pt->suivant = NULL; + + + } + + + } + + +} +void addFilm(tableReal table,char nom[LINE_MAX],char prenom[LINE_MAX] ) +{ + ptrealisateur pt = findReal(table,nom,prenom); + ptoeuvres ptOe = 0; + ptOe = pt->filmographie; + int X = 0; + char anne[LINE_MAX]; + char tittle[LINE_MAX]; + char commentaire[LINE_MAX]; +if(ptOe != NULL) +{ + while(ptOe->suivant != NULL) + { + ptOe = ptOe->suivant; + } +} +else X = 1; + + ptoeuvres newOe = malloc(sizeof(Oeuvres)); + initOeuvre(newOe); + printf("ajouter un film : \ntitre : "); + scanf("%s",&tittle); + printf("annee : "); + scanf("%s",&anne); + printf("commentaire : "); + scanf("%s",&commentaire); + memcpy(newOe->commentaire,commentaire,strlen(commentaire)+1); + memcpy(newOe->title,tittle,strlen(tittle)+1); + memcpy(newOe->annee,anne,strlen(anne)+1); +if(X == 0) + ptOe->suivant = newOe; +else + pt->filmographie = newOe; +} + +int eraseFilm(ptrealisateur real,char title[LINE_MAX]) +{ + ptoeuvres previousOe = real->filmographie; + ptoeuvres nextOe = real->filmographie->suivant; + if(previousOe == NULL) + return 1; + if(nextOe == NULL) + { + if(strcmp(previousOe->title,title) == 0) + { + real->filmographie = NULL; + } + return 1; + } + + +if(nextOe != NULL) +{ + + + while(strcmp(nextOe->title,title) != 0 && (previousOe != NULL && nextOe != nextOe)) + { + previousOe = nextOe; + nextOe = nextOe->suivant; + if(nextOe == NULL) + return 1; + } + previousOe->suivant = nextOe->suivant; + free(nextOe); +} +else +{ + if(strcmp(nextOe->title,title) == 0) + { + free(nextOe); + previousOe->suivant = NULL; + return 1; + } + else if(strcmp(previousOe->title,title) == 0) + { + real->filmographie = nextOe; + free(previousOe); + return 1; + } + + +} + printf("%s n'existe pas \n",title); + + + return 0; + +} + + + +void eraseReal(tableReal table,char nom[LINE_MAX],char prenom[LINE_MAX]) +{ + ptrealisateur pt = findReal(table,nom,prenom); + ptoeuvres ptOe = pt->filmographie->suivant; + if(pt != NULL) + { + printf("effacement en court \n"); + while(pt->filmographie != NULL) + { + pt->filmographie = ptOe->suivant; + ptOe = ptOe->suivant; + } + table[hashNum(nom,prenom)] = NULL; + free(ptOe); + free(pt); + } + +} +void commande() +{ + printf("que voulez vous faire ? \n1 = afficher les realisteurs\n2 = chercher et selectionner un realisteur\n3 = afficher le realisateur selectionner\n4 = effacer le realisateur selectionner\n5 = ajouter un film au realisateur selectionner\n6 = effacer un film au realisateur selectioner\n7 = ajouter un realisateur\n8 = quitter \n"); +} +void menu(tableReal table) +{ + int QUITTER = 0; + int choix = 0; + char nom[LINE_MAX]; + char prenom[LINE_MAX]; + char nomNew[LINE_MAX]; + char prenomNew[LINE_MAX]; + char titre[LINE_MAX]; + ptrealisateur pt = NULL; + commande(); + + while(QUITTER==0) + { + while(choix == 0) + { + scanf("%d",&choix); + if(choix > 8 || choix < 0) + choix = 0; + system("cls"); + } + switch(choix) + { + + case 1: + { + commande(); + afficherTable(table); + choix = 0; + break; + } + case 2: + { + commande(); + printf("chercher, nom : "); + scanf("%s",&nom); + printf("prenom : "); + scanf("%s",&prenom); + pt = findReal(table,nom,prenom); + choix = 0; + break; + } + case 3: + { + commande(); + if(pt != NULL) + afficherReal(table,pt->nom,pt->prenom); + else + printf("pas de realisateur selectionner !"); + + choix = 0; + break; + } + case 4: + { + commande(); + if(pt != NULL) + eraseReal(table,pt->nom,pt->prenom); + else + printf("pas de realisateur selectionner !"); + + choix = 0; + break; + } + + case 5: + { + commande(); + if(pt != NULL) + addFilm(table,pt->nom,pt->prenom); + else + printf("pas de realisateur selectionner !"); + + choix = 0; + break; + } + case 6: + { + commande(); + if(pt != NULL) + { + printf("nom du film à effacer :"); + scanf("%s",titre); + eraseFilm(pt,titre); + } + else + printf("pas de realisateur selectionner !"); + + choix = 0; + break; + } + case 7: + { + commande(); + printf("ajouter : nom : "); + scanf("%s",&nomNew); + printf("prenom : "); + scanf("%s",&prenomNew); + addReal(table,nomNew,prenomNew); + + choix = 0; + break; + } + case 8: + { + printf("au revoir !"); + QUITTER = 1; + break; + } + + + } + + + } + + +} +void init() +{ + + tableReal table; + initTable(table); + FILE* fichier = NULL; + fichier = fopen("very_small_example.list", "r+"); + readFile(fichier,table); + fclose(fichier); + + menu(table); + +} +int main() +{ + + init(); + return 0; +} diff --git a/rapport_cuadros_zhang_programmationavancee.pdf b/rapport_cuadros_zhang_programmationavancee.pdf new file mode 100755 index 0000000..cd6095a Binary files /dev/null and b/rapport_cuadros_zhang_programmationavancee.pdf differ -- libgit2 0.21.2