Advertisement
Guest User

Untitled

a guest
May 20th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <string.h>
  5.  
  6. //////////////////////////////////////
  7. //////// les prototypres //////////
  8. //////////////////////////////////////
  9. void menu_principale(void);
  10. void menu_pile(void);
  11. void desempiler(void);
  12. void menu_FIFO(void);
  13. void supprimer_FIFO(void);
  14. void menu_file_p(void);
  15. void inserer_p(void);
  16. void supprimer_p(void);
  17. void afficher_p(void);
  18.  
  19. void inserer(char *);
  20. void initialiser(char *);
  21. void afficher(char *);
  22.  
  23. void current_menu(char *);
  24. //////////////////////////////////////
  25. //////// menu principale //////////
  26. //////////////////////////////////////
  27. void menu_principale()
  28. {
  29. char choix;
  30. int x=40,y=9,i;
  31. gotoxy(x-2,y-1);
  32. for(i=0;i<32;i++)
  33. printf("%c",205);
  34. system("COLOR 0B");
  35. gotoxy(x-2,y-1);
  36. printf("%c",201);
  37. gotoxy(x+29,y-1);
  38. printf("%c",187);
  39. gotoxy(x+7,y);
  40. printf("MENU PRINCIPALE\n");
  41.  
  42. gotoxy(x-2,++y);
  43. for(i=0;i<32;i++)
  44. printf("%c",205);
  45. system("COLOR 0B");
  46. gotoxy(x-2,y);
  47. printf("%c",201);
  48. gotoxy(x+29,y);
  49. printf("%c",187);
  50.  
  51.  
  52. gotoxy(x,++y);
  53. printf("1- Pile\n");
  54. gotoxy(x,++y);
  55. printf("2- File d'attente(FIFO)\n");
  56. gotoxy(x,++y);
  57. printf("3- File d'attente(Priorite)\n");
  58. gotoxy(x,++y);
  59. printf("4- Quitter\n\n");
  60. gotoxy(x,y+2);
  61. printf("VOTRE CHOIX :");
  62. gotoxy(x+13,y+2);
  63. choix=getch();
  64. switch(choix) {
  65. case '1' :
  66. clrscr();
  67. menu_pile();
  68. break;
  69. case '2' :
  70. clrscr();
  71. menu_FIFO();
  72. break;
  73. case '3' :
  74. clrscr();
  75. menu_file_p();
  76. break;
  77. case '4' :
  78. exit(0);
  79. break;
  80. default :
  81. clrscr();
  82. system("COLOR 0C");
  83. gotoxy(x,y+1);
  84. for(i=0;i<34;i++)
  85. printf("%c",205);
  86. gotoxy(x,y+1);
  87. printf("%c",200);
  88. gotoxy(x+34,y+1);
  89. printf("%c",188);
  90. gotoxy(x+1,y);
  91. printf(" votre choix n'est pas correct ! \n");
  92. getch();
  93. system("COLOR 0B");
  94. clrscr();
  95. menu_principale();
  96. }
  97.  
  98. }
  99. //////////////////////////////////////
  100. /////////// menu pile /////////////
  101. //////////////////////////////////////
  102.  
  103. void menu_pile()
  104. {
  105. char choix,nom[] ="pile.txt";
  106. int x=40,y=9,i;
  107. gotoxy(x-2,y-1);
  108. for(i=0;i<32;i++)
  109. printf("%c",205);
  110. system("COLOR 0B");
  111. gotoxy(x-2,y-1);
  112. printf("%c",201);
  113. gotoxy(x+29,y-1);
  114. printf("%c",187);
  115. gotoxy(x+9,y);
  116. printf("MENU PILE\n");
  117.  
  118. gotoxy(x-2,++y);
  119. for(i=0;i<32;i++)
  120. printf("%c",205);
  121. system("COLOR 0B");
  122. gotoxy(x-2,y);
  123. printf("%c",201);
  124. gotoxy(x+29,y);
  125. printf("%c",187);
  126.  
  127.  
  128. gotoxy(x,++y);
  129. printf("1- initialiser\n");
  130. gotoxy(x,++y);
  131. printf("2- empiler(FIFO)\n");
  132. gotoxy(x,++y);
  133. printf("3- desempiler\n");
  134. gotoxy(x,++y);
  135. printf("4- afficher\n\n");
  136. gotoxy(x,++y);
  137. printf("5- retourner\n\n");
  138. gotoxy(x,++y+1);
  139. printf("VOTRE CHOIX :");
  140. gotoxy(x+13,y+1);
  141. fflush(stdin);
  142. choix=getch();
  143. switch(choix) {
  144. case '1' :
  145. clrscr();
  146. initialiser(nom);
  147. break;
  148. case '2' :
  149. clrscr();
  150. inserer(nom);
  151. break;
  152. case '3' :
  153. clrscr();
  154. desempiler();
  155. break;
  156. case '4' :
  157. clrscr();
  158. afficher(nom);
  159. break;
  160. case '5' :
  161. clrscr();
  162. menu_principale();
  163. break;
  164. default :
  165. clrscr();
  166. system("COLOR 0C");
  167. gotoxy(x,y+1);
  168. for(i=0;i<34;i++)
  169. printf("%c",205);
  170. gotoxy(x,y+1);
  171. printf("%c",200);
  172. gotoxy(x+34,y+1);
  173. printf("%c",188);
  174. gotoxy(x+1,y);
  175. printf(" votre choix n'est pas correct ! \n");
  176. getch();
  177. system("COLOR 0B");
  178. clrscr();
  179. menu_pile();
  180. }
  181.  
  182. }
  183. //////////////////////////////////////
  184. /////////// menu FIFO /////////////
  185. //////////////////////////////////////
  186. void menu_FIFO()
  187. {
  188. char choix,nom[] ="file.txt";
  189. int x=40,y=9,i;
  190. gotoxy(x-2,y-1);
  191. for(i=0;i<32;i++)
  192. printf("%c",205);
  193. system("COLOR 0B");
  194. gotoxy(x-2,y-1);
  195. printf("%c",201);
  196. gotoxy(x+29,y-1);
  197. printf("%c",187);
  198. gotoxy(x+7,y);
  199. printf("MENU FILE (FIFO)\n");
  200.  
  201. gotoxy(x-2,++y);
  202. for(i=0;i<32;i++)
  203. printf("%c",205);
  204. system("COLOR 0B");
  205. gotoxy(x-2,y);
  206. printf("%c",201);
  207. gotoxy(x+29,y);
  208. printf("%c",187);
  209.  
  210.  
  211. gotoxy(x,++y);
  212. printf("1- initialiser\n");
  213. gotoxy(x,++y);
  214. printf("2- inserer\n");
  215. gotoxy(x,++y);
  216. printf("3- supprimer");
  217. gotoxy(x,++y);
  218. printf("4- afficher\n\n");
  219. gotoxy(x,++y);
  220. printf("5- retourner\n\n");
  221. gotoxy(x,++y+1);
  222. printf("VOTRE CHOIX :");
  223. gotoxy(x+13,y+1);
  224. choix=getch();
  225. switch(choix) {
  226. case '1' :
  227. clrscr();
  228. initialiser(nom);
  229. break;
  230. case '2' :
  231. clrscr();
  232. inserer(nom);
  233. break;
  234. case '3' :
  235. clrscr();
  236. supprimer_FIFO();
  237. break;
  238. case '4' :
  239. clrscr();
  240. afficher(nom);
  241. break;
  242. case '5' :
  243. clrscr();
  244. menu_principale();
  245. break;
  246. default :
  247. clrscr();
  248. system("COLOR 0C");
  249. gotoxy(x,y+1);
  250. for(i=0;i<34;i++)
  251. printf("%c",205);
  252. gotoxy(x,y+1);
  253. printf("%c",200);
  254. gotoxy(x+34,y+1);
  255. printf("%c",188);
  256. gotoxy(x+1,y);
  257. printf(" votre choix n'est pas correct ! \n");
  258. getch();
  259. system("COLOR 0B");
  260. clrscr();
  261. menu_FIFO();
  262. }
  263.  
  264. }
  265. //////////////////////////////////////
  266. /////// menu File priorité ///////////
  267. //////////////////////////////////////
  268. void menu_file_p()
  269. {
  270. char choix,nom[] ="filep.txt";
  271. int x=40,y=9,i;
  272. gotoxy(x-2,y-1);
  273. for(i=0;i<32;i++)
  274. printf("%c",205);
  275. system("COLOR 0B");
  276. gotoxy(x-2,y-1);
  277. printf("%c",201);
  278. gotoxy(x+29,y-1);
  279. printf("%c",187);
  280. gotoxy(x+4,y);
  281. printf("MENU FILE PAR PRIORITE\n");
  282.  
  283. gotoxy(x-2,++y);
  284. for(i=0;i<32;i++)
  285. printf("%c",205);
  286. system("COLOR 0B");
  287. gotoxy(x-2,y);
  288. printf("%c",201);
  289. gotoxy(x+29,y);
  290. printf("%c",187);
  291. gotoxy(x,++y);
  292. printf("1- initialiser\n");
  293. gotoxy(x,++y);
  294. printf("2- inserer\n");
  295. gotoxy(x,++y);
  296. printf("3- supprimer");
  297. gotoxy(x,++y);
  298. printf("4- afficher\n\n");
  299. gotoxy(x,++y);
  300. printf("5- retourner\n\n");
  301. gotoxy(x,++y+1);
  302. printf("VOTRE CHOIX :");
  303. gotoxy(x+13,y+1);
  304. choix=getch();
  305. switch(choix) {
  306. case '1' :
  307. clrscr();
  308. initialiser(nom);
  309. break;
  310. case '2' :
  311. clrscr();
  312. inserer_p();
  313. break;
  314. case '3' :
  315. clrscr();
  316. supprimer_p();
  317. break;
  318. case '4' :
  319. clrscr();
  320. afficher_p();
  321. break;
  322. case '5' :
  323. clrscr();
  324. menu_principale();
  325. break;
  326. default :
  327. clrscr();
  328. system("COLOR 0C");
  329. gotoxy(x,y+1);
  330. for(i=0;i<34;i++)
  331. printf("%c",205);
  332. gotoxy(x,y+1);
  333. printf("%c",200);
  334. gotoxy(x+34,y+1);
  335. printf("%c",188);
  336. gotoxy(x+1,y);
  337. printf(" votre choix n'est pas correct ! \n");
  338. getch();
  339. system("COLOR 0B");
  340. clrscr();
  341. menu_file_p();
  342. }
  343.  
  344. }
  345. /////////////////////////////////////--FONCTION D'AIDE--/////////////////////////////////////
  346.  
  347. //////////////////////////////////////
  348. ////////// menu actuelle /////////////
  349. //////////////////////////////////////
  350. void current_menu(char nom[]){
  351. if(strcmp(nom,"pile.txt")==0)
  352. menu_pile();
  353. else{
  354. if(strcmp(nom,"file.txt")==0)
  355. menu_FIFO();
  356. else
  357. menu_file_p();
  358. }
  359. }
  360.  
  361. /////////////////////////////////////--LES SOUS FONCTIONS--/////////////////////////////////////
  362.  
  363. //////////////////////////////////////
  364. ///// PILE & FIFO & FILE PRIORITE ////
  365. ///////////initialisation/////////////
  366. //////////////////////////////////////
  367. void initialiser(char nom[]){
  368. FILE *p;
  369. char reponse;
  370. int tire,x=25,y=16;
  371.  
  372. //system("COLOR 0C");
  373. gotoxy(x,y+1);
  374. for(tire=0;tire<64;tire++)
  375. printf("%c",205);
  376. gotoxy(x,y+1);
  377. printf("%c",200);
  378. gotoxy(x+64,y+1);
  379. printf("%c",188);
  380. gotoxy(x+1,y);
  381. printf("vous etes sur que vous voulez initialiser votre %s?(y/n)\n",nom);
  382. fflush(stdin);
  383. gotoxy(x+66,y);
  384. reponse=getchar();
  385. switch(reponse){
  386. case 'y':
  387. p=fopen(nom,"wt");
  388. fclose(p);
  389. break;
  390. case 'n':
  391. break;
  392. default:
  393. clrscr();
  394. system("COLOR 0C");
  395. gotoxy(x+20,y+1);
  396. for(tire=0;tire<33;tire++)
  397. printf("%c",205);
  398. gotoxy(x+20,y+1);
  399. printf("%c",200);
  400. gotoxy(x+53,y+1);
  401. printf("%c",188);
  402. gotoxy(x+21,y);
  403. printf(" votre choix n'est pas correct ! \n");
  404. getch();
  405. system("COLOR 0B");
  406. }
  407. clrscr();
  408. current_menu(nom);
  409.  
  410. }
  411. //////////////////////////////////////
  412. /////////// PILE & FIFO ////////////
  413. //////////////insertion///////////////
  414. //////////////////////////////////////
  415. void inserer(char nom[]){
  416.  
  417. char old[20],element;
  418. FILE *p,*ptmp;
  419. int i=0,j,tire,x=32,y=13;
  420. p=fopen(nom,"rt");
  421. if(p!=NULL){
  422. ptmp=fopen("temp.txt","wt");
  423. while((old[i]=fgetc(p))!=EOF)
  424. {
  425. i++;
  426. }
  427. fclose(p);
  428. gotoxy(x,y);
  429. printf("> inserer votre element : ");
  430. gotoxy(x+1,y+1);
  431. for(tire=0;tire<23;tire++)
  432. printf("%c",205);
  433. fflush(stdin);
  434. gotoxy(x+26,y);
  435. element=getchar();
  436. for(j=0;j<i;j++){
  437. fprintf(ptmp,"%c",old[j]);
  438. }
  439. fprintf(ptmp,"%c",element);
  440. fclose(ptmp);
  441. clrscr();
  442. system("COLOR 0A");
  443. gotoxy(x,y+1);
  444. for(tire=0;tire<53;tire++)
  445. printf("%c",205);
  446. gotoxy(x+1,y);
  447. printf("votre element: %c a ete bien inserer dans :<%s>\n",element,nom);
  448. remove(nom);
  449. rename("temp.txt",nom);
  450. getch();
  451. clrscr();
  452. current_menu(nom);
  453. }
  454. else{
  455. system("COLOR 0A");
  456. gotoxy(x-6,y+1);
  457. for(tire=0;tire<35;tire++)
  458. printf("%c",205);
  459. gotoxy(x-6,y);
  460. printf("%s sera cree attendez vous...",nom);
  461. sleep(3);
  462. clrscr();
  463. initialiser(nom);
  464. clrscr();
  465. }
  466.  
  467. }
  468. //////////////////////////////////////
  469. ////////// FILE PRIORITE ///////////
  470. ///////////initialisation/////////////
  471. //////////////////////////////////////
  472. void inserer_p(){
  473. char elements[20],element,tempc;
  474. FILE *p,*ptmp;
  475. int i=0,j,k,priorites[20],tempd,priorite,tire,x=32,y=13;
  476.  
  477. p=fopen("filep.txt","rt");
  478. if(p!=NULL){
  479. ptmp=fopen("temp.txt","wt");
  480. while( (fscanf(p,"%c%d",&elements[i],&priorites[i]) !=EOF ))
  481. {
  482. i++;
  483. }
  484. fclose(p);
  485.  
  486.  
  487.  
  488. gotoxy(x,y);
  489. printf("> inserer votre element : ");
  490. gotoxy(x+2,y+1);
  491. for(tire=0;tire<22;tire++)
  492. printf("%c",205);
  493. fflush(stdin);
  494.  
  495.  
  496. gotoxy(x,y+3);
  497. printf("> inserer sa priorite : ");
  498. gotoxy(x+2,y+4);
  499. for(tire=0;tire<22;tire++)
  500. printf("%c",205);
  501.  
  502. gotoxy(x+26,y);
  503. fflush(stdin);
  504. element=getchar();
  505.  
  506. gotoxy(x+26,y+3);
  507. scanf("%d",&priorite);
  508.  
  509. elements[i+1]=element;
  510. priorites[i+1]=priorite;
  511.  
  512. for(j=0;j<i+1;j++){
  513. fprintf(ptmp,"%c%d",elements[j],priorites[j]);
  514. }
  515. fclose(ptmp);
  516. clrscr();
  517. system("COLOR 0A");
  518. gotoxy(x-12,y+1);
  519. for(tire=0;tire<74;tire++)
  520. printf("%c",205);
  521. gotoxy(x-12,y);
  522. printf(" votre element: %c a ete bien inserer dans la file d'attente avec priorite\n",element);
  523. remove("filep.txt");
  524. rename("temp.txt","filep.txt");
  525. getch();
  526. clrscr();
  527. menu_file_p();
  528. }
  529. else{
  530.  
  531. system("COLOR 0A");
  532. gotoxy(x-6,y+1);
  533. for(tire=0;tire<30;tire++)
  534. printf("%c",205);
  535. gotoxy(x-6,y);
  536. printf("la file priorite sera cree...");
  537. sleep(2);
  538. clrscr();
  539. initialiser("filep.txt");
  540.  
  541. }
  542.  
  543. }
  544. //////////////////////////////////////
  545. /////////////// PILE ///////////////
  546. //////////// SUPPRESSION /////////////
  547. //////////////////////////////////////
  548. void desempiler(){
  549. char old[20],c;
  550. FILE *p,*ptmp;
  551. int i=0,j,tire,x=25,y=16;
  552. p=fopen("pile.txt","rt");
  553.  
  554. if(p!=NULL){
  555. ptmp=fopen("temp.txt","wt");
  556. while((c=fgetc(p))!=EOF)
  557. {
  558. old[i]=c;
  559. i++;
  560. }
  561. fclose(p);
  562. if(i==0)
  563. {
  564. system("COLOR 0C");
  565. gotoxy(x+20,y+1);
  566. for(tire=0;tire<20;tire++)
  567. printf("%c",205);
  568. gotoxy(x+20,y+1);
  569. printf("%c",200);
  570. gotoxy(x+40,y+1);
  571. printf("%c",188);
  572. gotoxy(x+21,y);
  573. printf(" la pile est vide !");
  574. getch();
  575. system("COLOR 0B");
  576. clrscr();
  577. }
  578. else{
  579. system("COLOR 0A");
  580. gotoxy(x+20,y+1);
  581. for(tire=0;tire<17;tire++)
  582. printf("%c",205);
  583. gotoxy(x+20,y+1);
  584. printf("%c",200);
  585. gotoxy(x+37,y+1);
  586. printf("%c",188);
  587. gotoxy(x+21,y);
  588. printf(" L'ELEMENT : %c ",old[i-1]);
  589. getch();
  590. system("COLOR 0B");
  591. clrscr();
  592. }
  593. for(j=0;j<i-1;j++){
  594. fprintf(ptmp,"%c",old[j]);
  595. }
  596. fclose(ptmp);
  597. remove("pile.txt");
  598. rename("temp.txt","pile.txt");
  599. clrscr();
  600. menu_pile();
  601. }
  602. else{
  603. fclose(p);
  604. system("COLOR 0C");
  605. gotoxy(x+20,y+1);
  606. for(tire=0;tire<23;tire++)
  607. printf("%c",205);
  608. gotoxy(x+20,y+1);
  609. printf("%c",200);
  610. gotoxy(x+43,y+1);
  611. printf("%c",188);
  612. gotoxy(x+21,y);
  613. printf(" la pile n'existe pas");
  614. getch();
  615. system("COLOR 0B");
  616. clrscr();
  617. initialiser("pile.txt");
  618. }
  619. }
  620.  
  621. //////////////////////////////////////
  622. /////////////// FIFO ///////////////
  623. ///////////// SUPPRESSION ///////////
  624. //////////////////////////////////////
  625. void supprimer_FIFO(){
  626. char old[20],c;
  627. FILE *p,*ptmp;
  628. int i=0,j,tire,x=25,y=16;
  629. p=fopen("file.txt","rt");
  630. if(p!=NULL){
  631. ptmp=fopen("temp.txt","wt");
  632. while((c=fgetc(p))!=EOF)
  633. {
  634. old[i]=c;
  635. i++;
  636. }
  637. fclose(p);
  638. if(i==0)
  639. {
  640.  
  641. system("COLOR 0C");
  642. gotoxy(x+20,y+1);
  643. for(tire=0;tire<20;tire++)
  644. printf("%c",205);
  645. gotoxy(x+20,y+1);
  646. printf("%c",200);
  647. gotoxy(x+40,y+1);
  648. printf("%c",188);
  649. gotoxy(x+21,y);
  650. printf(" la pile est vide !");
  651. getch();
  652. system("COLOR 0B");
  653. clrscr();
  654.  
  655. }
  656. else
  657. {
  658. system("COLOR 0A");
  659. gotoxy(x+20,y+1);
  660. for(tire=0;tire<17;tire++)
  661. printf("%c",205);
  662. gotoxy(x+20,y+1);
  663. printf("%c",200);
  664. gotoxy(x+37,y+1);
  665. printf("%c",188);
  666. gotoxy(x+21,y);
  667. printf(" L'ELEMENT : %c ",old[0]);
  668. getch();
  669. system("COLOR 0B");
  670. clrscr();
  671. }
  672.  
  673. for(j=1;j<i;j++){
  674. fprintf(ptmp,"%c",old[j]);
  675. }
  676. fclose(ptmp);
  677. fclose(p);
  678. remove("file.txt");
  679. rename("temp.txt","file.txt");
  680. menu_FIFO();
  681. }
  682. else{
  683. system("COLOR 0C");
  684. gotoxy(x+20,y+1);
  685. for(tire=0;tire<23;tire++)
  686. printf("%c",205);
  687. gotoxy(x+20,y+1);
  688. printf("%c",200);
  689. gotoxy(x+43,y+1);
  690. printf("%c",188);
  691. gotoxy(x+21,y);
  692. printf(" la file n'existe pas");
  693. getch();
  694. system("COLOR 0B");
  695. clrscr();
  696. initialiser("file.txt");
  697. }
  698. }
  699. //////////////////////////////////////
  700. ////////// PILE & FIFO /////////////
  701. ///////////// AFFICHAGE /////////////
  702. //////////////////////////////////////
  703. void afficher(char nom[]){
  704. char old[20];
  705. FILE *p;
  706. int i=0,j,tire,tireb,x=32,y=13,k;
  707. p=fopen(nom,"rt");
  708. if(p!=NULL){
  709. while((old[i]=fgetc(p))!=EOF)
  710. {
  711. i++;
  712. }
  713. fclose(p);
  714. if(strcmp("file.txt",nom)==0)
  715. {
  716. system("COLOR 0A");
  717. gotoxy(x-4,y-1);
  718. for(tire=0;tire<i*12;tire++){
  719. printf("%c",205);
  720. }
  721.  
  722. gotoxy(x-4,y);
  723. printf("%c",186);
  724. gotoxy(x-2,y);
  725. for(j=0;j<i;j++){
  726. printf(" %c %c",old[j],186);
  727. }
  728.  
  729.  
  730. gotoxy(x-4,y+1);
  731. for(tire=0;tire<i*12;tire++){
  732. printf("%c",205);
  733. }
  734. }
  735. else{
  736. system("COLOR 0A");
  737. y=8;
  738. x=x+20;
  739. for(j=i;j>=0;j--)
  740. {
  741. if(i==j)
  742. {
  743. gotoxy(x,y);
  744. printf("-------\n");
  745. gotoxy(x,++y);
  746. printf("| |<==SOMMET\n");
  747. gotoxy(x,++y);
  748. printf("-------\n");
  749. }
  750. else{
  751. gotoxy(x,++y);
  752. printf("-------\n");
  753. gotoxy(x,++y);
  754. printf("| %c |\n",old[j]);
  755. gotoxy(x,++y);
  756. printf("-------\n");
  757. }
  758. }
  759. }
  760. getch();
  761. clrscr();
  762. current_menu(nom);
  763. }
  764. else{
  765. system("COLOR 0A");
  766. gotoxy(x-6,y+1);
  767. for(tire=0;tire<35;tire++)
  768. printf("%c",205);
  769. gotoxy(x-6,y);
  770. printf("%s sera cree attendez vous...",nom);
  771. sleep(3);
  772. clrscr();
  773. initialiser(nom);
  774. clrscr();
  775. }
  776. }
  777. //////////////////////////////////////
  778. //////////// FILE PRIORITE ///////////
  779. ///////////// SUPPRESSION ///////////
  780. //////////////////////////////////////
  781. void supprimer_p(){
  782. char priorites[20],elements[20],tempc;
  783. FILE *p,*ptmp;
  784. int i=0,j,k,tempd,x=25,y=14,tire;
  785. p=fopen("filep.txt","rt");
  786. ptmp=fopen("temp.txt","wt");
  787. if(p!=NULL){
  788. while( (fscanf(p,"%c%d",&elements[i],&priorites[i]) !=EOF ))
  789. {
  790. i++;
  791. }
  792. if(i==0){
  793.  
  794. system("COLOR 0C");
  795. gotoxy(x+20,y+1);
  796. for(tire=0;tire<20;tire++)
  797. printf("%c",205);
  798. gotoxy(x+20,y+1);
  799. printf("%c",200);
  800. gotoxy(x+40,y+1);
  801. printf("%c",188);
  802. gotoxy(x+21,y);
  803. printf(" la file est vide !");
  804. getch();
  805. system("COLOR 0B");
  806. clrscr();
  807.  
  808.  
  809. fclose(p);
  810. fclose(ptmp);
  811. remove("temp.txt");
  812. menu_file_p();
  813. }
  814. else{
  815. /* k=0;
  816. for(j=0;j<i;j++){
  817. if(priorites[k]<priorites[j]){
  818. tempd=priorites[j];
  819. priorites[j]=priorites[k];
  820. priorites[k]=tempd;
  821.  
  822. tempc=elements[j];
  823. elements[j]=elements[k];
  824. elements[k]=tempc;
  825. }
  826. }*/
  827.  
  828. fclose(p);
  829. system("COLOR 0A");
  830. gotoxy(x+21,y+1);
  831. for(tire=0;tire<13;tire++)
  832. printf("%c",205);
  833. gotoxy(x+21,y);
  834. printf("> ELEMENT :%c",elements[0]);
  835.  
  836. gotoxy(x+21,y+4);
  837. for(tire=0;tire<13;tire++)
  838. printf("%c",205);
  839. gotoxy(x+21,y+3);
  840. printf("> PRIORITE :%d",priorites[0]);
  841.  
  842. getch();
  843. system("COLOR 0B");
  844. clrscr();
  845. for(j=1;j<i;j++){
  846. fprintf(ptmp,"%c%d",elements[j],priorites[j]);
  847. }
  848. fclose(ptmp);
  849. remove("filep.txt");
  850. rename("temp.txt","filep.txt");
  851. sleep(1);
  852. clrscr();
  853. menu_file_p();
  854. }
  855. }
  856. else{
  857. system("COLOR 0C");
  858. gotoxy(x+20,y+1);
  859. for(tire=0;tire<23;tire++)
  860. printf("%c",205);
  861. gotoxy(x+20,y+1);
  862. printf("%c",200);
  863. gotoxy(x+43,y+1);
  864. printf("%c",188);
  865. gotoxy(x+21,y);
  866. printf(" la file n'existe pas");
  867. getch();
  868. system("COLOR 0B");
  869. clrscr();
  870. initialiser("filep.txt");
  871. }
  872. }
  873. //////////////////////////////////////
  874. //////////// FILE PRIORITE ///////////
  875. ///////////// AFFICHAGE /////////////
  876. //////////////////////////////////////
  877. void afficher_p(){
  878. char elements[20];
  879. FILE *p;
  880. int i=0,j,priorites[20],tire,x=32,y=13;
  881.  
  882. p=fopen("filep.txt","rt");
  883. if(p!=NULL){
  884. while( (fscanf(p,"%c%d",&elements[i],&priorites[i]) !=EOF ))
  885. {
  886. i++;
  887. }
  888. fclose(p);
  889. for(j=0;j<i;j++){
  890. system("COLOR 0A");
  891. gotoxy(x-4,y-1);
  892. for(tire=0;tire<i*12;tire++){
  893. printf("%c",205);
  894. }
  895.  
  896. gotoxy(x-4,y);
  897. printf("%c",186);
  898. gotoxy(x-2,y);
  899. for(j=0;j<i;j++){
  900. printf(" %c %c",elements[j],186);
  901. }
  902.  
  903.  
  904. gotoxy(x-4,y+1);
  905. for(tire=0;tire<i*12;tire++){
  906. printf("%c",205);
  907. }
  908. }
  909. y=y+3;
  910. for(j=0;j<i;j++){
  911. system("COLOR 0A");
  912. gotoxy(x-4,y-1);
  913. for(tire=0;tire<i*12;tire++){
  914. printf("%c",205);
  915. }
  916.  
  917. gotoxy(x-4,y);
  918. printf("%c",186);
  919. gotoxy(x-2,y);
  920. for(j=0;j<i;j++){
  921. printf(" %d %c",priorites[j],186);
  922. }
  923.  
  924.  
  925. gotoxy(x-4,y+1);
  926. for(tire=0;tire<i*12;tire++){
  927. printf("%c",205);
  928. }
  929. }
  930.  
  931. }
  932. else{
  933. system("COLOR 0A");
  934. gotoxy(x-6,y+1);
  935. for(tire=0;tire<35;tire++)
  936. printf("%c",205);
  937. gotoxy(x-6,y);
  938. printf("la file avec priorite sera cree ...");
  939. sleep(3);
  940. clrscr();
  941. initialiser("filep.txt");
  942. clrscr();
  943. }
  944. getch();
  945. clrscr();
  946. menu_file_p();
  947.  
  948. }
  949.  
  950. /////////////////////////////////////--LA FONCTION PRINCIPALE--/////////////////////////////////////
  951.  
  952. //////////////////////////////////////
  953. ////////////// main ///////////////
  954. //////////////////////////////////////
  955. int main()
  956. {
  957. menu_principale();
  958. return 0;
  959. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement