#include #include #include #include #include #define TAILLE 100 typedef struct motcle { char mot[30]; struct motcle *svt; }motcle; typedef struct msg { int code; char util[20]; char thematique[30]; char titre[30]; char corps[1000]; motcle *mot_cle; struct msg *svt; struct msg *rep; }msg; typedef struct theme { char nomdetheme[30]; msg *ptrlistmsg; }theme; typedef struct struct_tri { int code; char titre[30]; }struct_tri; theme *T[TAILLE]; int n=0,code=1; void ajouttheme(char *nom); void ajouter_mot_cle(motcle *mot_cle,char *mot) ; void deposer_sujet(char *theme,char*titre,char*corps,char *util,motcle *mot_cle); void repondre(msg *message,char*titre,char*corps,char *util,motcle *mot_cle); void afficher_theme_ordre_inser(void); void tri_nom(char *tab[]); void afficher_theme_ordre_alphabetique(void); void afficher_msg_hierar_msg(msg * message); void afficher_msg_hierar(void); void MenuPrincipal(void); void menu_ajout_theme(void); void menu_deposer_sujet(void); void trouver_message_dans_msg(msg *msg_rech,msg *racine,int code_msg); void trouver_message(int code_msg,msg *msg_rech); void menu_after_afficher(void); void menu_afficher(void); void debut(void); void ajouttheme(char *nom) { int i=0; FILE *f_theme=NULL,*nouveau_file=NULL; f_theme=fopen("themes.txt","at"); while(inomdetheme,nom); p->ptrlistmsg=NULL; T[i]=p; printf("un nouveau thème vient d'être ajouté"); fprintf(f_theme,"%s \n",nom); nouveau_file=fopen(nom,"w"); fclose(nouveau_file); n++; } fclose(f_theme); } else printf("erreur"); return; } void ajouter_mot_cle(motcle *mot_cle,char *mot) //utilisée dans deposer sujet// { motcle *p; motcle *nouveau=(motcle*)malloc(sizeof(motcle)); if(nouveau==NULL) printf("pas assez de memoire"); else { strcpy(nouveau->mot,mot); nouveau->svt=NULL; p=mot_cle; if(p==NULL) { mot_cle=nouveau; printf("le mot cle a bien ete ajouter"); } else { if(p->svt==NULL) p->svt=nouveau; else { while(p->svt!=NULL) p=p->svt; p->svt=nouveau; } printf("le mot cle a bien ete ajouter"); } } return ; } void deposer_sujet(char *theme,char*titre,char*corps,char *util,motcle *mot_cle) { int i=0; msg *p; msg *nouveau=(msg *)malloc(sizeof(msg)); if (nouveau==NULL) printf("il est impossible d'ajouter un nouveau message"); else { nouveau->code=code; strcpy(nouveau->thematique,theme); strcpy(nouveau->titre,titre); strcpy(nouveau->corps,corps); strcpy(nouveau->util,util); nouveau->mot_cle=mot_cle; nouveau->svt=NULL; nouveau->rep=NULL; while(strcmp(T[i]->nomdetheme,theme)!=0) i++; p=T[i]->ptrlistmsg; if(p==NULL) { T[i]->ptrlistmsg=nouveau; } else { while(p->svt!=NULL) p=p->svt; p->svt=nouveau; } code++; printf("le sujet a bien ete depose"); } return; } void repondre(msg *message,char*titre,char*corps,char *util,motcle *mot_cle) { msg *p=NULL; msg *nouveau=(msg *)malloc(sizeof(msg)); if (nouveau==NULL) printf("il est impossible de repondre a ce sujet\n"); else { nouveau->code=code; strcpy(nouveau->thematique,message->thematique); strcpy(nouveau->titre,titre); strcpy(nouveau->corps,corps); strcpy(nouveau->util,util); nouveau->mot_cle=mot_cle; nouveau->svt=NULL; nouveau->rep=NULL; p=message->rep; if(p==NULL) p=nouveau; else { if(p->svt==NULL) p->svt=nouveau; else { while(p->svt!=NULL) p=p->svt; p->svt=nouveau; } } code++; printf("le message a bien ete depose"); } return; } void afficher_theme_ordre_inser() { int i=0; { if (n==0) printf("aucun thème n\'a encore été saisi"); else { printf("les themes enregistres par ordre d'insertion sont:\n"); while(inomdetheme); i++; } } } return; } void tri_nom(char *tab[]) { int i=0,j=0; char *ech=NULL; for(i=0;i0) { strcpy(ech,tab[i]); strcpy(tab[i],tab[j]); strcpy(tab[j],ech); } } return; } void afficher_theme_ordre_alphabetique() { int i=0,j=0; char *p=NULL; if(n==0) printf("aucun theme n'a encore ete saisi"); else { char *copie[n]; while(inomdetheme); copie[i]=p; i++; } tri_nom(copie); while(jcode,message->titre); afficher_msg_hierar_msg(message->rep); afficher_msg_hierar_msg(message->svt); } return; } void afficher_msg_hierar() { int i; system("cls"); if(n==0) printf("aucun theme n'a ete depose"); else { for(i=0;inomdetheme); if(T[i]->ptrlistmsg==0) printf("\t\t ce theme ne contient aucun sujet\n"); else afficher_msg_hierar_msg(T[i]->ptrlistmsg); } } return; } void MenuPrincipal() { system("cls"); printf("\n\n\t\t*****************************************\n"); printf("\t\t** selectionnez l'operation que vous desirez faire: **\n\t\t*****************************************\n\n"); printf("\n\t 1 : Ajouter un theme. \n\n\t"); printf("\n\t 2 : Deposer un sujet. \n\n\t"); printf("\n\t 3 : Affciher la liste des themes ou des messages . \n\n\t"); printf("\n\t 0 : Quitter\n\n\t"); return; } void menu_ajout_theme() { char nom[30]; system("cls"); printf("entrez le thème que vous voulez ajouter \n"); scanf("%s",nom); ajouttheme(nom); return; } void menu_deposer_sujet() { int i=0,choix=1; char theme[30],titre[20],corp[1000],util[20],mot[30]; motcle *mot_cle=NULL; system("cls"); printf("entrez le thème"); scanf("%s",theme); while((inomdetheme,theme)!=0)) i++; if(i==n) printf("ce thème n'existe pas"); else { printf("entrez le titre du message"); scanf("%s",titre); printf("entrez le corps de votre message"); scanf("%s",corp); printf("entrez votre pseudo"); scanf("%s",util); while(choix==1) { printf("voulez-vous ajouter un mot clé? ,si oui tapez 1 sinon tapez 0"); scanf("%d",&choix); if(choix==1) { printf("entrez le mot clé"); scanf("%s",mot); ajouter_mot_cle(mot_cle,mot); } else break; } deposer_sujet(theme,titre,corp,util,mot_cle); } return; } void trouver_message_dans_msg(msg *msg_rech,msg *racine,int code_msg) { if(racine==NULL) return; else { if(racine->code==code_msg) {msg_rech=racine; return ;} else { trouver_message_dans_msg(msg_rech,racine->rep,code_msg); trouver_message_dans_msg(msg_rech,racine->svt,code_msg); } } return; } void trouver_message(int code_msg,msg *msg_rech) { int i=0; while((msg_rech==NULL)&&(iptrlistmsg,code_msg); i++; } return; } void menu_after_afficher() { int choix=0; msg *msg_rech=(msg*)malloc(sizeof(msg)); int choix2=0,choix1=0; char corps[1000],util[20],titre[30],mot[30]; motcle *mot_cle=(motcle *)malloc(sizeof(motcle)); printf("\n*********************************************************\n"); printf(" entrer le code du message auquel vous voulez repondre ou supprimer\n"); printf(" sinon tapez 0 pour revenir au menu principal \n\n"); scanf("%d",&choix1); if(choix1==0) MenuPrincipal(); else { system("cls"); printf("\n\n**************************************************\n"); printf("\n\t choisissez l'operation que vous voulez effectuer\n"); printf("\n\t 1 : repondre au message\n"); printf("\n\t 2 : supprimer le message\n"); printf("\n\n \t ATTENTION:la suppression du message entrainera la suppression de toutes ses reponses\n\n"); scanf("%d",&choix2); switch(choix2) { case 1: trouver_message(choix2,msg_rech); if(msg_rech==NULL) printf("ce message n'existe pas "); else { printf("entrer le titre de votre reponse"); scanf("%s",titre); printf("entrer le corps de votre reponse"); scanf("%s",corps); printf("entrer votre pseudo"); scanf("%s",util); do { printf("voulez-vous ajouter un mot clé? ,si oui tapez 1 sinon tapez 0"); scanf("%d",&choix); if(choix==1) { printf("entrez le mot clé"); scanf("%s",mot); ajouter_mot_cle(mot_cle,mot); } else break; } while(choix==1); repondre(msg_rech,titre,corps,util,mot_cle); break; } } } return; } void menu_afficher() { int choix; system("cls"); printf("******************************************\t\n"); printf("choisissez quel affichage vous desirez\n"); printf("\n\t 1 : Affichage des themes tries pr ordre d'insertion . \n\n\t"); printf("\n\t 2 : Affichage des themes tries pr ordre alphabétique .\n\n\t"); printf("\n\t 3 : Affichage des messages par ordre ordre hierarchique \n\n\t"); printf("\n\t 0 : pour revenir au menu initial . \n\n\t"); scanf("%d",&choix); if(choix!=1 && choix!=2 &&choix!=3 &&choix!=4 &&choix!=0) menu_afficher(); switch(choix) { case 1:afficher_theme_ordre_inser(); getch(); break; case 2:afficher_theme_ordre_alphabetique(); getch(); break; case 3:afficher_msg_hierar(); getch(); menu_after_afficher(); break; case 0: break; } } void debut() { int choix; do { MenuPrincipal(); scanf("%d",&choix); if(choix!=0&&choix!=1&&choix!=2&&choix!=3) MenuPrincipal(); else { switch(choix) { case 1: menu_ajout_theme(); getch(); break; case 2: menu_deposer_sujet(); getch(); break; case 3: menu_afficher(); getch(); break; case 0: exit(0); } } }while(choix!=0); } int main() { debut(); getch(); return 0; }