Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX 30
- #define MAXDATE 12
- /****************************************
- * Declaration des structures
- ************************************/
- typedef struct
- {
- int jour;
- char mois[MAXDATE];
- int annee;
- }Date;
- typedef struct
- {
- char nom[MAX];
- char prenom[MAX];
- Date dateNaissance;
- long numTelephone;
- }Personne;
- /****************************************
- * Prototype et variable globale
- ************************************/
- Personne *personne=NULL;
- void saisirInfo(Personne *pers);
- void afficherInfo(Personne *pers);
- void trierInfo(Personne *pers);
- int menu();
- int NBR=0;
- /****************************************
- * fonction main
- ************************************/
- int main()
- {
- int continuer=1,choix;
- do
- {
- choix=menu();
- switch(choix)
- {
- case 1:
- saisirInfo(personne);
- break;
- case 2:
- if(NBR!=0) afficherInfo(personne);
- else printf("\nVous ne pouvez pas afficher une liste vide !!");
- }
- }while(continuer);
- free(personne);
- system("pause");
- return 0;
- }
- /****************************************
- * fonction afficher avec allocation dynamique
- ************************************/
- void saisirInfo(Personne *pers)
- {
- int nbrPersonne,i;
- do
- {
- printf("Combien de personne voulez-vous ajouter ?\n");
- scanf("%d",&nbrPersonne);
- }while(nbrPersonne<=0);
- personne=malloc(nbrPersonne * sizeof(Personne));
- if(personne==NULL) exit(0);
- for(i=0;i<nbrPersonne;i++)
- {
- printf("\n****************************************\n");
- printf("Remplissage de la personne n : %d \n",i+1);
- printf("Le nom de la personne : ");
- scanf("%s",personne[i].nom);
- printf("Le prenom de la personne : ");
- scanf("%s",personne[i].prenom);
- printf("Le numero de telephone de la personne : ");
- scanf("%ld",&personne[i].numTelephone);
- printf("La date de naissance, exemple(05 mai 1990) : ");
- scanf("%d %s %d",&personne[i].dateNaissance.jour,personne[i].dateNaissance.mois,&personne[i].dateNaissance.annee);
- NBR++;
- }
- }
- /****************************************
- * Afficher le menu du choix
- ************************************/
- int menu()
- {
- int choix;
- do
- {
- printf("*******************************************\n");
- printf("Ce programme sert comme Annuaire de telephone \n");
- printf("Pour choisir une option du menu, Entrez le numero du choix :\n");
- printf("1. Ajouter des personne.\n");
- printf("2. Afficher les informations.\n");
- printf("3. Triez les noms des personne.\n");
- printf("4. Afficher la liste triee.\n");
- printf("5. chercher le numeo de tel d une personne.\n");
- printf("6. Quittez.\n");
- scanf("%d",&choix);
- }while(choix<1 || choix>6);
- return choix;
- }
- /****************************************
- * Afficher les infos
- ************************************/
- void afficherInfo(Personne *pers)
- {
- int i;
- printf("Affichage de la liste des personnes enregistrees dans l annuaire :");
- for(i=0;i<NBR;i++)
- {
- printf("la personne n: %d\n",i+1);
- 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);
- printf("\tNumero de telephone : %ld\n",pers[i].numTelephone);
- printf("---------------------------------------------------\n");
- }
- }
- /****************************************
- * Trier le tableau
- ************************************/
- void trierInfo(Personne *pers)
- {
- int i,j;
- for(i=0;i<NBR;i++)
- for(j=0;j<NBR;j++)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment