diff --git a/main.c b/main.c index cd52091..e319fa5 100644 --- a/main.c +++ b/main.c @@ -1,222 +1,151 @@ -#include -#include -#define NBC 20 -#define NBO 40 -#define NBF 10 -#define LINE_MAX 1000 +#include "fonction.h" +//explication de l'utilisation du menu -#include - - - -typedef struct Oeuvres Oeuvres; -struct Oeuvres -{ - char title[LINE_MAX]; - char annee[LINE_MAX]; - char commentaire[LINE_MAX]; - Oeuvres *suivant; - -}; - - -typedef Oeuvres *ptoeuvres, *liste_chaine; - - -typedef struct Realisateur Realisateur; -struct Realisateur +void commande() { - char nom[LINE_MAX]; - char prenom[LINE_MAX]; - ptoeuvres filmographe; - Realisateur *suivant; -}; - -typedef Realisateur *ptrealisateur, *liste_realisateur; - -typedef struct -{ - Realisateur realisateur; - ptrealisateur suivant; - -}REALISATEUR; - - -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; - + 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 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); +// Menu du programme - readPartOfLine(begin,Pbegin,element,film->title); - - readPartOfLine(Pbegin+1,Pend,element,film->annee); - - readPartOfLine(Pend+1,end,element,film->commentaire); - printf("titre : %s , annee : %s , commentaire : %s \n",film->title,film->annee,film->commentaire); - - -} -int findEnd(char line[LINE_MAX]) -{ - int av = 0; - while(line[av] != '\n') - av++; - return av; -} -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 = malloc(sizeof(Oeuvres)); - - -} -void readFile(FILE *file, ptrealisateur database) +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(); - - char line[LINE_MAX]; - int av = 0; - - int first = 0; - - int virgule = 0; - int tab = 0; - int end = 0; - - char element[LINE_MAX]; - - - - ptrealisateur actualReal = database; - ptoeuvres actualOeuvre = NULL; - - - actualReal->filmographe = malloc(sizeof(Oeuvres)); - actualOeuvre = actualReal->filmographe; - - - - - - char *ret; - while(av == 0) + while(QUITTER==0) { - - if(fgets(line,LINE_MAX,file) != NULL) + 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; + } - ret = strpbrk(line,","); - if(ret != NULL) + 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) { - - if(first == 1) - { - - actualReal->suivant = malloc(sizeof(Realisateur)); - actualReal = actualReal->suivant; - actualReal->filmographe = malloc(sizeof(Oeuvres)); - actualOeuvre = actualReal->filmographe; - initOeuvre(actualOeuvre); - } - - - first = 1; - - virgule = ret - line; - tab = strpbrk(line,"\t") - line; - end = findEnd(line); - readPartOfLine(0,virgule,line,actualReal->nom); - readPartOfLine(virgule+1,tab,line,actualReal->prenom); - - printf("nom : %s prenom : %s \n",actualReal->nom,actualReal->prenom); - - readPartOfLine(tab+1,end,line,element); - - readElement(element,actualOeuvre); - - - actualOeuvre = actualOeuvre->suivant; - - - + printf("nom du film à effacer :"); + scanf("%s",titre); + eraseFilm(pt,titre); } - else if(strcmp(line,"\n") != 0) - { - - - - initOeuvre(actualOeuvre); - - - - readElement(line,actualOeuvre); - - actualOeuvre = actualOeuvre->suivant; - + 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; + } - } } - else - av = 1; - } + } +// Initialisation de tous les paramètres -int main() +void init() { - - Realisateur database; - ptrealisateur ptDataBase = &database; - database.filmographe = malloc(sizeof(Oeuvres)); - initOeuvre(database.filmographe); + tableReal table; + initTable(table); FILE* fichier = NULL; fichier = fopen("very_small_example.list", "r+"); + readFile(fichier,table); + fclose(fichier); - readFile(fichier,ptDataBase); + menu(table); +} +int main() +{ + init(); return 0; } -- libgit2 0.21.2