Voila la fonction tri avec en fin les free
/********************************************************************************
* *
* Fonction : tri_tar *
* *
* Objet : Tri du tar pour affichege *
* *
********************************************************************************/
void tri_tar (struct tar ** p, int nb, char * critere) {
/*------------------------------ DECLARATIONS ------------------------*/
int i,j=0, kmax=0;
struct tar * tempo1;
char DateKmax[12];
char DateJ [12];
int numpara = 0;
int indice = 0;
char * p_tmp;
/*---------------------------- DEBUT DE TRAITEMENT --------------------*/
p_tmp = (char * ) malloc (255);
tempo1 = (struct tar *) calloc (1,sizeof (struct tar));
//Boucles de tri
for (i = 0 ; i < nb ; i++) {
kmax = i;
for (j = i+1; j <= nb ; j++) {
if (!strcmp(critere,"droits")) if (strcmp (p[kmax]->droits,p[j]->droits) > 0) kmax = j;
if (!strcmp(critere,"groupe")) if (strcmp (p[kmax]->groupe,p[j]->groupe) > 0) kmax = j;
if (!strcmp(critere,"chemin")) if (strcmp (p[kmax]->chemin,p[j]->chemin) > 0) kmax = j;
if (!strcmp(critere,"nom")) if (strcmp (p[kmax]->nom, p[j]->nom) > 0) kmax = j;
if (!strcmp(critere,"taille")) if (atoi(p[kmax]->taille) > atoi(p[j]->taille)) kmax = j;
if (!strcmp(critere,"date")) {
//Extraction de la date de kmax
numpara = 0;
indice = 0;
while (p[kmax]->date [indice]!='\0') {
//"indice" est incrémenté par scanligne
scanligne (p[kmax]->date,p_tmp,&indice, '-', '\0');
switch (numpara) {
case 0:
strcpy (DateKmax,p_tmp); break;
case 1:
strcat (DateKmax,p_tmp); break;
case 2:
strcat (DateKmax,p_tmp); break;
}
numpara++;
}
//Extraction de la date de j
numpara = 0;
indice = 0;
while (p[j]->date [indice]!='\0') {
//"indice" est incrémenté par scanligne
scanligne (p[j]->date,p_tmp,&indice, '-', '\0');
switch (numpara) {
case 0:
strcpy (DateJ,p_tmp); break;
case 1:
strcat (DateJ,p_tmp); break;
case 2:
strcat (DateJ,p_tmp); break;
}
numpara++;
}
if (atoi(DateKmax) > atoi(DateJ)) kmax = j;
}
}
//Permutation des valeur après compar aision de deux valeurs
tempo1 = p[kmax];
p[kmax] = p[i] ;
p[i] = tempo1;
}
//strcpy(tempo1.nom,"VIDE");
tempo1=0;
free (tempo1 );
free (p_tmp );
}