bonsoir
voila un code qui contient 3 fonctions :
-fonction pour un remplir un tableau de structure
-fonction pour trier ce tableau
-fonction pour l'affichage
voila ce que j'ai fait
Code c : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<stdio.h>
#include<conio.h>
struct etudiant{
       char nom[30] ;
       char prenom[30];
       int age ;
       char sexe[2] ;
       };
void rem(struct etudiant *p , int *n){
     int i ;
 
     printf("entrez le nombre d'etudiants");
     scanf("%d",n);
     for(i=0 ; i<(*n) ; i++)
     {
             printf("etudiant no : %d " , i+1);
             printf("entrez le nom de cet etudiant");
             scanf("%s",&(*(p+i)).nom);
             printf("entrez le prenom de cet etudiant");
             scanf("%s",&(*(p+i)).prenom);
             printf("entrez l'age de cet etudiant");
             scanf("%d",&(*(p+i)).age);
             printf("entrez le sexe de cet etudiant F pour femme , H pour homme");
             scanf("%s",&(*(p+i)).sexe);
             }
             }
void tri(struct etudiant *p , int *n )
{
     int i , j , posmax   ;
     struct etudiant per ;
     for(i=0 ; i<(*n)-1 ; i++)
     {
             posmax=i ;
             for(j=i+1 ; j<(*n) ; j++)
             {
                       if((*(p+j)).age>(*(p+posmax)).age)
                       posmax=j ;
                       }
              per=*(p+i) ;
              *(p+i)=*(p+posmax) ;
              *(p+posmax)=per ;
              }
              }
void  affi(struct etudiant *p , int *n)
{
      int i ;
      for(i=0 ; i<(*n) ; i++)
      {
              printf("%s",(*(p+i)).nom);
              printf("\n");
              printf("%s",(*(p+i)).prenom);
               printf("\n");
              printf("%d",(*(p+i)).age);
               printf("\n");
              printf("%s",(*(p+i)).sexe);
               printf("\n");
              }
              }
int main(){
    struct etudiant t[100] ;
    int n ;
 
             rem(t , &n) ;
             tri(t , &n ) ;
             affi(t , &n);
             getch();
             }


- est ce que code la est suffisant .
- je veux savoir s'il ya une methode plus élégante et plus professionelle pour traiter ce probleme . surtout au niveau de la fonction tri .