Se connecter avec
S'enregistrer | Connectez-vous

Projet de gestion d'un forum en c

Dernière réponse : dans Programmation

bonjour,
je dois rendre un projet en c qui repose sur la gestion d'un forum en c :
ce qui est demander est de deposer de nouveaux thèmes ,ajouter des sujets,afficher la liste des thèmes/sujets .... et plusieurs autres fonction .

j'ai utilisé pour cela les structures suivantes:


  1. typedef struct motcle
  2. {
  3. char mot[30];
  4. struct motcle *svt;
  5. }motcle;
  6.  
  7.  
  8.  
  9.  
  10. typedef struct msg
  11. {
  12. int code;
  13. char util[20];
  14. char thematique[30];
  15. char titre[30];
  16. char corps[1000];
  17. motcle *mot_cle;
  18. struct msg *svt;
  19. struct msg *rep;
  20. }msg;
  21.  
  22.  
  23.  
  24. typedef struct theme
  25. {
  26. char nomdetheme[30];
  27. msg *ptrlistmsg;
  28. }theme;



et j'ai defini comme variables globales:


theme *T[TAILLE];
int n=0; //determine la taille du tableau (nombre de thèmes insérer)
int code=1; //determine le nombre de msg déposer pour incrémenter le code des messages


j'ai deja réaliser la fonction ajouttheme et deposer_sujet qui se compilent et s'executent sans problème
  1. void ajouttheme(char *nom)
  2. {
  3. int i=0;
  4. FILE *f_theme=NULL,*nouveau_file=NULL;
  5. f_theme=fopen("themes.txt","at");
  6. while(i<n) i++;
  7. if(f_theme!=NULL)
  8. {
  9. if(i==TAILLE) printf("impossible d'ajouter un autre thème");
  10. else
  11. {
  12. theme *p=(theme *)malloc(sizeof(theme));
  13. strcpy(p->nomdetheme,nom);
  14. p->ptrlistmsg=NULL;
  15. T[i]=p;
  16. printf("un nouveau thème vient d'être ajouté");
  17. fprintf(f_theme,"%s \n",nom);
  18. nouveau_file=fopen(nom,"w");
  19. fclose(nouveau_file);
  20. n++;
  21. }
  22. fclose(f_theme);
  23. }
  24. else printf("erreur");
  25. return;
  26. }
  27.  
  28.  
  29. void ajouter_mot_cle(motcle *mot_cle,char *mot) //utilisée dans deposer sujet//
  30. {
  31. motcle *p;
  32. motcle *nouveau=(motcle*)malloc(sizeof(motcle));
  33. if(nouveau==NULL) printf("pas assez de memoire");
  34. else
  35. {
  36. strcpy(nouveau->mot,mot);
  37. nouveau->svt=NULL;
  38. p=mot_cle;
  39. if(p==NULL)
  40. {
  41. mot_cle=nouveau;
  42. printf("le mot cle a bien ete ajouter");
  43. }
  44. else
  45. {
  46. if(p->svt==NULL) p->svt=nouveau;
  47. else
  48. {
  49. while(p->svt!=NULL) p=p->svt;
  50. p->svt=nouveau;
  51. }
  52.  
  53. printf("le mot cle a bien ete ajouter");
  54. }
  55. }
  56. return ;
  57. }
  58.  
  59.  
  60.  
  61. void deposer_sujet(char *theme,char*titre,char*corps,char *util,motcle *mot_cle)
  62. {
  63. int i=0;
  64. msg *p;
  65. msg *nouveau=(msg *)malloc(sizeof(msg));
  66. if (nouveau==NULL) printf("il est impossible d'ajouter un nouveau message");
  67. else
  68. {
  69. nouveau->code=code;
  70. strcpy(nouveau->thematique,theme);
  71. strcpy(nouveau->titre,titre);
  72. strcpy(nouveau->corps,corps);
  73. strcpy(nouveau->util,util);
  74. nouveau->mot_cle=mot_cle;
  75. nouveau->svt=NULL;
  76. nouveau->rep=NULL;
  77.  
  78.  
  79. while(strcmp(T[i]->nomdetheme,theme)!=0) i++;
  80. p=T[i]->ptrlistmsg;
  81. if(p==NULL)
  82. {
  83. T[i]->ptrlistmsg=nouveau;
  84. }
  85. else
  86. {
  87.  
  88. while(p->svt!=NULL) p=p->svt;
  89.  
  90. p->svt=nouveau;
  91. }
  92. code++;
  93. printf("le sujet a bien ete depose");
  94. }
  95. return;
  96. }


par contre dans la fonction repondre ,il n'ya pas de probleme du coté compilation mais ca bugge lors de l'execution.


  1. void repondre(msg *message,char*titre,char*corps,char *util,motcle *mot_cle)
  2. {
  3. msg *p=NULL;
  4. msg *nouveau=(msg *)malloc(sizeof(msg));
  5. if (nouveau==NULL) printf("il est impossible de repondre a ce sujet\n");
  6. else
  7. {
  8. nouveau->code=code;
  9. strcpy(nouveau->thematique,message->thematique);
  10. strcpy(nouveau->titre,titre);
  11. strcpy(nouveau->corps,corps);
  12. strcpy(nouveau->util,util);
  13. nouveau->mot_cle=mot_cle;
  14. nouveau->svt=NULL;
  15. nouveau->rep=NULL;
  16.  
  17. p=message->rep;
  18. if(p==NULL) p=nouveau;
  19. else
  20. {
  21. if(p->svt==NULL) p->svt=nouveau;
  22. else
  23. {
  24. while(p->svt!=NULL) p=p->svt;
  25. p->svt=nouveau;
  26. }
  27.  
  28. }
  29. code++;
  30. printf("le message a bien ete depose");
  31. }
  32. return;
  33. }

ca fait 4jours que je coince a ce stade si vous pouvez s'il vous plait m'aider

Autres pages sur : projet gestion forum

Lassé par la pub ? Créez un compte

voila la partie du programme qui cause problème


  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<conio.h>
  5. #define TAILLE 100
  6.  
  7.  
  8.  
  9.  
  10.  
  11. typedef struct motcle
  12. {
  13. char mot[30];
  14. struct motcle *svt;
  15. }motcle;
  16.  
  17.  
  18.  
  19.  
  20. typedef struct msg
  21. {
  22. int code;
  23. char util[20];
  24. char thematique[30];
  25. char titre[30];
  26. char corps[1000];
  27. motcle *mot_cle;
  28. struct msg *svt;
  29. struct msg *rep;
  30. }msg;
  31.  
  32.  
  33.  
  34. typedef struct theme
  35. {
  36. char nomdetheme[30];
  37. msg *ptrlistmsg;
  38. }theme;
  39.  
  40.  
  41. typedef struct struct_tri
  42. {
  43. int code;
  44. char titre[30];
  45. }struct_tri;
  46.  
  47.  
  48.  
  49. theme *T[TAILLE];
  50. int n=0,code=1;
  51.  
  52. void ajouttheme(char *nom);
  53. void ajouter_mot_cle(motcle *mot_cle,char *mot) ;
  54. void deposer_sujet(char *theme,char*titre,char*corps,char *util,motcle *mot_cle);
  55. void repondre(msg *message,char*titre,char*corps,char *util,motcle *mot_cle);
  56. void afficher_theme_ordre_inser();
  57. void tri_nom(char *tab[]);
  58. void afficher_theme_ordre_alphabetique();
  59. void afficher_msg_hierar_msg(msg * message);
  60. void afficher_msg_hierar();
  61. void MenuPrincipal();
  62. void menu_ajout_theme();
  63. void menu_deposer_sujet();
  64. void trouver_message_dans_msg(msg *msg_rech,msg *message,int code_msg);
  65. msg* trouver_message(int code_msg);
  66. void menu_after_afficher();
  67. void menu_afficher();
  68. void debut();
  69.  
  70.  
  71. void ajouttheme(char *nom)
  72. {
  73. int i=0;
  74. FILE *f_theme=NULL,*nouveau_file=NULL;
  75. f_theme=fopen("themes.txt","at");
  76. while(i<n) i++;
  77. if(f_theme!=NULL)
  78. {
  79. if(i==TAILLE) printf("impossible d'ajouter un autre thème");
  80. else
  81. {
  82. theme *p=(theme *)malloc(sizeof(theme));
  83. strcpy(p->nomdetheme,nom);
  84. p->ptrlistmsg=NULL;
  85. T[i]=p;
  86. printf("un nouveau thème vient d'être ajouté");
  87. fprintf(f_theme,"%s \n",nom);
  88. nouveau_file=fopen(nom,"w");
  89. fclose(nouveau_file);
  90. n++;
  91. }
  92. fclose(f_theme);
  93. }
  94. else printf("erreur");
  95. return;
  96. }
  97.  
  98.  
  99.  
  100.  
  101. void ajouter_mot_cle(motcle *mot_cle,char *mot) //utilisée dans deposer sujet//
  102. {
  103. motcle *p;
  104. motcle *nouveau=(motcle*)malloc(sizeof(motcle));
  105. if(nouveau==NULL) printf("pas assez de memoire");
  106. else
  107. {
  108. strcpy(nouveau->mot,mot);
  109. nouveau->svt=NULL;
  110. p=mot_cle;
  111. if(p==NULL)
  112. {
  113. mot_cle=nouveau;
  114. printf("le mot cle a bien ete ajouter");
  115. }
  116. else
  117. {
  118. if(p->svt==NULL) p->svt=nouveau;
  119. else
  120. {
  121. while(p->svt!=NULL) p=p->svt;
  122. p->svt=nouveau;
  123. }
  124.  
  125. printf("le mot cle a bien ete ajouter");
  126. }
  127. }
  128. return ;
  129. }
  130.  
  131.  
  132.  
  133. void deposer_sujet(char *theme,char*titre,char*corps,char *util,motcle *mot_cle)
  134. {
  135. int i=0;
  136. msg *p;
  137. msg *nouveau=(msg *)malloc(sizeof(msg));
  138. if (nouveau==NULL) printf("il est impossible d'ajouter un nouveau message");
  139. else
  140. {
  141. nouveau->code=code;
  142. strcpy(nouveau->thematique,theme);
  143. strcpy(nouveau->titre,titre);
  144. strcpy(nouveau->corps,corps);
  145. strcpy(nouveau->util,util);
  146. nouveau->mot_cle=mot_cle;
  147. nouveau->svt=NULL;
  148. nouveau->rep=NULL;
  149.  
  150.  
  151. while(strcmp(T[i]->nomdetheme,theme)!=0) i++;
  152. p=T[i]->ptrlistmsg;
  153. if(p==NULL)
  154. {
  155. T[i]->ptrlistmsg=nouveau;
  156. }
  157. else
  158. {
  159.  
  160. while(p->svt!=NULL) p=p->svt;
  161.  
  162. p->svt=nouveau;
  163. }
  164. code++;
  165. printf("le sujet a bien ete depose");
  166. }
  167. return;
  168. }
  169.  
  170.  
  171.  
  172.  
  173. void repondre(msg *message,char*titre,char*corps,char *util,motcle *mot_cle)
  174. {
  175. msg *p=NULL;
  176. msg *nouveau=(msg *)malloc(sizeof(msg));
  177. if (nouveau==NULL) printf("il est impossible de repondre a ce sujet\n");
  178. else
  179. {
  180. nouveau->code=code;
  181. strcpy(nouveau->thematique,message->thematique);
  182. strcpy(nouveau->titre,titre);
  183. strcpy(nouveau->corps,corps);
  184. strcpy(nouveau->util,util);
  185. nouveau->mot_cle=mot_cle;
  186. nouveau->svt=NULL;
  187. nouveau->rep=NULL;
  188.  
  189. p=message->rep;
  190. if(p==NULL) p=nouveau;
  191. else
  192. {
  193. if(p->svt==NULL) p->svt=nouveau;
  194. else
  195. {
  196. while(p->svt!=NULL) p=p->svt;
  197. p->svt=nouveau;
  198. }
  199.  
  200. }
  201. code++;
  202. printf("le message a bien ete depose");
  203. }
  204. return;
  205. }
  206.  
  207.  
  208.  
  209. void afficher_theme_ordre_inser()
  210. {
  211. int i=0;
  212.  
  213. {
  214. if (n==0) printf("aucun thème n\'a encore été saisi");
  215. else
  216. {
  217. printf("les themes enregistres par ordre d'insertion sont:\n");
  218. while(i<n)
  219. {
  220. printf("%d/ %s \n",i+1,T[i]->nomdetheme);
  221. i++;
  222. }
  223. }
  224. }
  225. return;
  226. }
  227.  
  228.  
  229.  
  230. void tri_nom(char *tab[])
  231. {
  232. int i=0,j=0;
  233. char *ech;
  234. for(i=0;i<n-1;i++)
  235. for(j=i+1;j<n;j++)
  236. {
  237. if((strcmp(tab[i],tab[j]))>0)
  238. {
  239. strcpy(ech,tab[i]);
  240. strcpy(tab[i],tab[j]);
  241. strcpy(tab[j],ech);
  242. }
  243. }
  244. return;
  245. }
  246.  
  247.  
  248.  
  249. void afficher_theme_ordre_alphabetique()
  250. {
  251. int i=0,j=0;
  252. char *copie[n];
  253. if(n==0) printf("aucun theme n'a encore ete saisi");
  254. else
  255. {
  256. while(i<n)
  257. {
  258. char *p=(char *)malloc(sizeof(char));
  259. strcpy(p,T[i]->nomdetheme);
  260. copie[i]=p;
  261. i++;
  262.  
  263. }
  264. tri_nom(copie);
  265. while(j<i)
  266. {
  267. printf("%d/ %s \n",j+1,copie[j]);
  268. j++;
  269. }
  270. for(i=0;i<n;i++) free(copie[i]);
  271. }
  272.  
  273. return;
  274. }
  275.  
  276. void afficher_msg_hierar_msg(msg * message)
  277. {
  278. if(message==NULL) return;
  279. else
  280. {
  281. printf("\t %d : %s \n",message->code,message->titre);
  282. afficher_msg_hierar_msg(message->rep);
  283. afficher_msg_hierar_msg(message->svt);
  284. }
  285. return;
  286. }
  287.  
  288. void afficher_msg_hierar()
  289. {
  290. int i;
  291. system("cls");
  292. if(n==0) printf("aucun theme n'a ete depose");
  293. else
  294. {
  295. for(i=0;i<n;i++)
  296. {
  297. printf("theme : %s\n",T[i]->nomdetheme);
  298. if(T[i]->ptrlistmsg==0) printf("\t\t ce theme ne contient aucun sujet\n");
  299. else
  300. afficher_msg_hierar_msg(T[i]->ptrlistmsg);
  301. }
  302. }
  303. return;
  304. }
  305.  
  306.  
  307. void MenuPrincipal()
  308. {
  309. system("cls");
  310. printf("\n\n\t\t*****************************************\n");
  311. printf("\t\t** selectionnez l'operation que vous desirez faire: **\n\t\t*****************************************\n\n");
  312. printf("\n\t 1 : Ajouter un theme. \n\n\t");
  313. printf("\n\t 2 : Deposer un sujet. \n\n\t");
  314. printf("\n\t 3 : Affciher la liste des themes ou des messages . \n\n\t");
  315. printf("\n\t 0 : Quitter\n\n\t");
  316. return;
  317. }
  318.  
  319. void menu_ajout_theme()
  320. {
  321. char nom[30];
  322. system("cls");
  323. printf("entrez le thème que vous voulez ajouter \n");
  324. scanf("%s",nom);
  325. ajouttheme(nom);
  326. return;
  327. }
  328.  
  329. void menu_deposer_sujet()
  330. {
  331. int i=0,choix=1;
  332. char theme[30],titre[20],corp[1000],util[20],mot[30];
  333. motcle *mot_cle=NULL;
  334. system("cls");
  335.  
  336. printf("entrez le thème");
  337. scanf("%s",theme);
  338. while((i<n) && (strcmp(T[i]->nomdetheme,theme)!=0)) i++;
  339. if(i==n) printf("ce thème n'existe pas");
  340. else
  341. {
  342. printf("entrez le titre du message");
  343. scanf("%s",titre);
  344. printf("entrez le corps de votre message");
  345. scanf("%s",corp);
  346. printf("entrez votre pseudo");
  347. scanf("%s",util);
  348. while(choix=1)
  349. {
  350. printf("voulez-vous ajouter un mot clé? ,si oui tapez 1 sinon tapez 0");
  351. scanf("%d",&choix);
  352. if(choix==1)
  353. {
  354. printf("entrez le mot clé");
  355. scanf("%s",mot);
  356. ajouter_mot_cle(mot_cle,mot);
  357. }
  358. else break;
  359. }
  360.  
  361.  
  362. deposer_sujet(theme,titre,corp,util,mot_cle);
  363. }
  364. return;
  365. }
  366.  
  367.  
  368. void trouver_message_dans_msg(msg *msg_rech,msg *message,int code_msg)
  369. {
  370. if(message->code==code_msg) {msg_rech=message; return ;}
  371. else
  372. {
  373. trouver_message_dans_msg(msg_rech,message->rep,code_msg);
  374. trouver_message_dans_msg(msg_rech,message->svt,code_msg);
  375. }
  376.  
  377. }
  378.  
  379. msg* trouver_message(int code_msg)
  380. {
  381. int i;
  382. msg *msg_rech=(msg*)malloc(sizeof(msg));
  383. msg *p=NULL;
  384. for(i=0;i<n;i++)
  385. {
  386. p=T[i]->ptrlistmsg;
  387. trouver_message_dans_msg(msg_rech,p,code_msg);
  388. }
  389. if(msg_rech==NULL) {printf("ce message n'existe pas");menu_after_afficher();}
  390. else return msg_rech;
  391. }
  392.  
  393.  
  394. void menu_after_afficher()
  395. {
  396. int choix=1;
  397. msg *message;
  398. int choix2=0,choix1=0;
  399. char corps[1000],util[20],titre[30],mot[30];
  400. motcle *mot_cle=(motcle *)malloc(sizeof(motcle));
  401. printf("\n*********************************************************\n");
  402. printf(" entrer le code du message auquel vous voulez repondre ou supprimer\n");
  403. printf(" sinon tapez 0 pour revenir au menu principal \n\n");
  404. scanf("%d",&choix1);
  405. if(choix1==0) MenuPrincipal();
  406. else
  407. {
  408. system("cls");
  409. printf("\n\n**************************************************\n");
  410. printf("\n\t choisissez l'operation que vous voulez effectuer\n");
  411. printf("\n\t 1 : repondre au message\n");
  412. printf("\n\t 2 : supprimer le message\n");
  413. printf("\n\n \t ATTENTION:la suppression du message entrainera la suppression de toutes ses reponses\n\n");
  414. scanf("%d",&choix2);
  415. switch(choix2)
  416. {
  417. case 1:
  418. message=trouver_message(choix1);
  419. printf("entrer le titre de votre reponse");
  420. scanf("%s",titre);
  421. printf("entrer le corps de votre reponse");
  422. scanf("%s",corps);
  423. printf("entrer votre pseudo");
  424. scanf("%s",util);
  425. while(choix=1)
  426. {
  427. printf("voulez-vous ajouter un mot clé? ,si oui tapez 1 sinon tapez 0");
  428. scanf("%d",&choix);
  429. if(choix==1)
  430. {
  431. printf("entrez le mot clé");
  432. scanf("%s",mot);
  433. ajouter_mot_cle(mot_cle,mot);
  434. }
  435. else break;
  436. }
  437. message=trouver_message(choix1);
  438. repondre(message,titre,corps,util,mot_cle);
  439. break;
  440. }
  441. }
  442. return;
  443. }
  444.  
  445.  
  446. void menu_afficher()
  447. {
  448. int choix;
  449. system("cls");
  450. printf("******************************************\t\n");
  451. printf("choisissez quel affichage vous desirez\n");
  452. printf("\n\t 1 : Affichage des themes tries pr ordre d'insertion . \n\n\t");
  453. printf("\n\t 2 : Affichage des themes tries pr ordre alphabétique .\n\n\t");
  454. printf("\n\t 3 : Affichage des messages par ordre ordre hierarchique \n\n\t");
  455. printf("\n\t 0 : pour revenir au menu initial . \n\n\t");
  456. scanf("%d",&choix);
  457. if(choix!=1 && choix!=2 &&choix!=3 &&choix!=4 &&choix!=0) menu_afficher();
  458. switch(choix)
  459. {
  460. case 1:afficher_theme_ordre_inser();
  461. getch();
  462. break;
  463. case 2:afficher_theme_ordre_alphabetique();
  464. getch();
  465. break;
  466. case 3:afficher_msg_hierar();
  467. getch();
  468. menu_after_afficher();
  469. break;
  470.  
  471. case 0: break;
  472. }
  473. }
  474.  
  475.  
  476.  
  477. void debut()
  478. {
  479. char choix;
  480. do
  481. {
  482. MenuPrincipal();
  483.  
  484. scanf("%d",&choix);
  485. if(choix!=0&&choix!=1&&choix!=2&&choix!=3&&choix!=4&&choix!=5)
  486. {
  487. MenuPrincipal();
  488. }
  489. else
  490. {
  491. switch(choix)
  492. {
  493. case 1: menu_ajout_theme();
  494. getch();
  495. break;
  496. case 2: menu_deposer_sujet();
  497. getch();
  498. break;
  499. case 3: menu_afficher();
  500. getch();
  501. break;
  502. case 0:
  503. exit(0);
  504. }
  505.  
  506. }
  507.  
  508. }while(choix!=0);
  509.  
  510. }
  511.  
  512.  
  513.  
  514. int main()
  515. {
  516.  
  517. debut();
  518. getch();
  519. getch();
  520. }
Lassé par la pub ? Créez un compte