bouchnina

Untitled

Feb 28th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define MAX 30
  4. #define MAXDATE 12
  5.  
  6.                         /****************************************
  7.                         *   Declaration des structures
  8.                         ************************************/
  9. typedef struct
  10. {
  11.     int jour;
  12.     char mois[MAXDATE];
  13.     int annee;
  14.  
  15. }Date;
  16. typedef struct
  17. {
  18.     char nom[MAX];
  19.     char prenom[MAX];
  20.     Date dateNaissance;
  21.     long numTelephone;
  22.  
  23. }Personne;
  24.  
  25.                         /****************************************
  26.                         *   Prototype et variable globale
  27.                         ************************************/
  28.  
  29. Personne *personne=NULL;
  30. void saisirInfo(Personne *pers);
  31. void afficherInfo(Personne *pers);
  32. void trierInfo(Personne *pers);
  33. int menu();
  34. int NBR=0;
  35.  
  36.                         /****************************************
  37.                         *   fonction main
  38.                         ************************************/
  39.  
  40. int main()
  41. {
  42.     int continuer=1,choix;
  43.     do
  44.     {
  45.         choix=menu();
  46.         switch(choix)
  47.         {
  48.             case 1:
  49.                 saisirInfo(personne);
  50.                 break;
  51.             case 2:
  52.                 if(NBR!=0)  afficherInfo(personne);
  53.                 else printf("\nVous ne pouvez pas afficher une liste vide !!");
  54.         }
  55.     }while(continuer);
  56.  
  57.  
  58.  
  59.     free(personne);
  60.     system("pause");
  61.     return 0;
  62. }
  63.  
  64.                         /****************************************
  65.                         *   fonction afficher avec allocation dynamique
  66.                         ************************************/
  67.  
  68. void saisirInfo(Personne *pers)
  69. {
  70.     int nbrPersonne,i;
  71.     do
  72.     {
  73.         printf("Combien de personne voulez-vous ajouter ?\n");
  74.         scanf("%d",&nbrPersonne);
  75.     }while(nbrPersonne<=0);
  76.  
  77.     personne=malloc(nbrPersonne * sizeof(Personne));
  78.  
  79.     if(personne==NULL)  exit(0);
  80.  
  81.     for(i=0;i<nbrPersonne;i++)
  82.         {
  83.             printf("\n****************************************\n");
  84.             printf("Remplissage de la personne n : %d \n",i+1);
  85.             printf("Le nom de la personne : ");
  86.             scanf("%s",personne[i].nom);
  87.             printf("Le prenom de la personne : ");
  88.             scanf("%s",personne[i].prenom);
  89.             printf("Le numero de telephone de la personne : ");
  90.             scanf("%ld",&personne[i].numTelephone);
  91.             printf("La date de naissance, exemple(05 mai 1990) : ");
  92.             scanf("%d %s %d",&personne[i].dateNaissance.jour,personne[i].dateNaissance.mois,&personne[i].dateNaissance.annee);
  93.             NBR++;
  94.         }
  95. }
  96.  
  97.                         /****************************************
  98.                         *   Afficher le menu du choix
  99.                         ************************************/
  100.  
  101. int menu()
  102. {
  103.     int choix;
  104.     do
  105.     {
  106.         printf("*******************************************\n");
  107.         printf("Ce programme sert comme Annuaire de telephone \n");
  108.         printf("Pour choisir une option du menu, Entrez le numero du choix :\n");
  109.         printf("1. Ajouter des personne.\n");
  110.         printf("2. Afficher les informations.\n");
  111.         printf("3. Triez les noms des personne.\n");
  112.         printf("4. Afficher la liste triee.\n");
  113.         printf("5. chercher le numeo de tel d une personne.\n");
  114.         printf("6. Quittez.\n");
  115.         scanf("%d",&choix);
  116.     }while(choix<1 || choix>6);
  117.     return choix;
  118.  
  119. }
  120.  
  121.                         /****************************************
  122.                         *   Afficher les infos
  123.                         ************************************/
  124.  
  125. void afficherInfo(Personne *pers)
  126.     {
  127.         int i;
  128.         printf("Affichage de la liste des personnes enregistrees dans l annuaire :");
  129.         for(i=0;i<NBR;i++)
  130.             {
  131.                 printf("la personne n: %d\n",i+1);
  132.                 printf("nom : %s\t prenom : %s\t ne en %d %s %d\n",pers[i].nom,pers[i].prenom,pers[i].dateNaissance.jour,pers[i].dateNaissance.mois,pers[i].dateNaissance.annee);
  133.                 printf("\tNumero de telephone : %ld\n",pers[i].numTelephone);
  134.                 printf("---------------------------------------------------\n");
  135.             }
  136.     }
  137.  
  138.  
  139.                         /****************************************
  140.                         *   Trier le tableau
  141.                         ************************************/
  142.  
  143. void trierInfo(Personne *pers)
  144. {
  145.     int i,j;
  146.     for(i=0;i<NBR;i++)
  147.         for(j=0;j<NBR;j++)
  148.             {
  149.                
  150.             }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment