| 12
 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
 
 |  
#include <stdio.h>
#include <stdlib.h>
 
typedef struct
{
        char c[12];
} T_type;
 
 
 
/* fonction utilisateur de comparaison fournie a qsort() */
static int compare (void const *a, void const *b)
{
   /* definir des pointeurs type's et initialise's
      avec les parametres */
   char const *const *pa = a;
   char const *const *pb = b;
 
   /* evaluer et retourner l'etat de l'evaluation (tri croissant) */
   return strcmp (*pa, *pb);
}
 
 
/* affichage du tableau */
static void aff (char const **a, size_t n)
{
   size_t i;
   for (i = 0; i < n; i++)
   {
      printf ("%s\n", a[i]);
   }
   printf ("\n");
}
 
 
int main(int argc, char *argv[])
{
 
  /* tableau a trier (tableau de pointeurs sur char const) */
   //char const *tab[] = { "100", "300", "200" };
 
   int *p = malloc(10*sizeof(int));
   T_type const *tab[4];
   *tab = malloc(4*sizeof(T_type));
 
   strcpy(tab[0], "c");
   strcpy(tab[1], "b");
   strcpy(tab[2], "a");
 
/* affichage du tableau dans l'etat */
   aff (tab, sizeof tab / sizeof *tab);
 
   qsort (tab, sizeof tab / sizeof *tab, sizeof *tab, compare);
 
/* affichage du tableau apres le tri */
   aff (tab, sizeof tab / sizeof *tab);
 
 
 
  system("PAUSE");	
 
 
 
  return 0;
} | 
Partager