Advertisement
lineoff

exemple_de_structure_fct

Dec 19th, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.49 KB | None | 0 0
  1. //
  2. //  main.c
  3. //  Structur_de_donnee
  4. //
  5. //  Created by MacBook Pro on 19/12/2015.
  6. //  Copyright © 2015 MacBook Pro. All rights reserved.
  7. //
  8.  
  9. #include <stdio.h>
  10. #include "stdbool.h"
  11. #include "string.h"
  12. #include "conio.h"
  13.  
  14. typedef struct {
  15.     int matricule;
  16.     double salaire;
  17.     char Nom[25],PreNom[25];
  18. }fonctionnaire;
  19. bool matriculeTrouve(fonctionnaire *fon){
  20.     int i=0;
  21.     int mat;
  22.     mat = fon[i].matricule;
  23.     for (i=1; i<30; i++) {
  24.         if(mat == fon[i].matricule){
  25.             return true;
  26.         }
  27.     }
  28.     return false;
  29. }
  30.  
  31. void fillTab(fonctionnaire *fon){
  32.     int i;
  33.     printf("Remplissage du tableau :\n");
  34.     for (i=0; i<30; i++) {
  35.         do{
  36.         printf("Donner le matricule du fonctionnaire: ");
  37.             scanf("%d",&fon[i].matricule);
  38.         }while(matriculeTrouve(fon));
  39.        
  40.         printf("Donner le salaire du fonctonnaire: ");
  41.         scanf("%lf",&fon[i].salaire);
  42.         getchar();
  43.        
  44.         printf("Donner le nom du fonctionnaier: ");
  45.         gets(fon[i].Nom);
  46.        
  47.         printf("Donner le prenom du fonctionnaier: ");
  48.         gets(fon[i].PreNom);
  49.     }
  50.    
  51. }
  52. void sort(fonctionnaire *fon){
  53.     int i,j;
  54.     fonctionnaire aide;
  55.     for (i=0; i<29; i++) {
  56.         for (j=i+1; j<30; j++) {
  57.             if (strcmp(fon[i].Nom,fon[j].Nom)>0) {
  58.                
  59.                 strcpy(aide.Nom, fon[i].Nom);
  60.                 strcpy(aide.PreNom, fon[i].PreNom);
  61.                 aide.matricule = fon[i].matricule;
  62.                 aide.salaire = fon[i].salaire;
  63.                
  64.                 strcpy(fon[i].Nom, fon[j].Nom);
  65.                 strcpy(fon[i].PreNom, fon[j].PreNom);
  66.                 fon[i].matricule = fon[j].matricule;
  67.                 fon[i].salaire = fon[j].salaire;
  68.                
  69.                 strcpy(fon[j].Nom, aide.Nom);
  70.                 strcpy(fon[j].PreNom, aide.PreNom);
  71.                 fon[j].matricule = aide.matricule;
  72.                 fon[j].salaire = aide.salaire;
  73.                
  74.             }
  75.         }
  76.     }
  77. }
  78. void printTab(fonctionnaire *fon){
  79.     int i;
  80.    
  81.     for (i=0; i<30; i++) {
  82.         printf("Nom: %s\nPrenom: %s\nMatricule: %d\nSalaire: %.2lf\n",((fon+i)->Nom),((fon+i)->PreNom),((fon+i)->matricule),((fon+i)->salaire));
  83.     }
  84.    
  85. }
  86. int main(int argc, const char * argv[]) {
  87.    
  88.     fonctionnaire t[30];
  89.    
  90.     fillTab(t);
  91.     printTab(t);
  92.     sort(t);
  93.     printf("\nle tableau apres le triage:\n");
  94.     printTab(t);
  95.    
  96.     getch();
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement