Exemple   008 :

 
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <llist.h> /* Ou #include "llist.h" */
LLIST *Lclt;
typedef struct
{
     long     numclient;
     int      departement;
     short    age;
     char     sexe;
     short    cadeau;
}CLT;
#define LCLT       sizeof(CLT)
#define OUI        1
#define NON        0
#define STRINIT(a) memset((char *)&a,0x0,sizeof(a))
CLT clt[]={
     {1000, 1,22,'M',0}, /*  1 client 1000, region 1 : Ain , Sex Masculin */
     {1003, 2,32,'F',0}, /*  2 */
     {1005, 5,42,'F',0}, /*  3 */
     {1004, 4,32,'F',0}, /*  4 */
     {1001, 3,62,'M',0}, /*  5 */
     {1012,13,72,'M',0}, /*  6 */
     {1011,14,72,'M',0}, /*  7 */
     {1006, 9,22,'F',0}, /*  8 */
     {1002, 6,32,'M',0}, /*  9 */
     {1008, 8,23,'M',0}, /* 10 */
     {1013, 7,28,'M',0}, /* 11 */
     {1009,10,44,'F',0}, /* 12 */
     {1010,11,44,'M',0}, /* 13 */
     {1007,12,56,'F',0}, /* 14 */
     { 0,0 , 0,' ',0}
};
/*-----------------------*/
/* Declaration Fonctions */
/*-----------------------*/
int cadeauxclt(void *);
int affclt(void *);
void affiche_liste_client(int ,char *);
void charge_list(LLIST **);

  
/*
------------------------------------------------------------------------------
main : programme d'aide sur les listes.
     : fonction lkey SetBKey UnSetBKey GetBkey laddtype
------------------------------------------------------------------------------
*/
void main(int argc,char **argv)
 {
     CLT T;
   if( initlist(&Lclt,LCLT,LLONG) == LOK ) /* creation d'1 liste L dont      la cle = LONG = numclient */
   {
       charge_list(&Lclt); /* charge la liste des clients */
       fprintf(stderr,"\n ----- AFFICHE LA LISTE DES CLIENTS --------\n");
       walk_FLD(&Lclt,affclt); /* affiche la liste des clients */
       fprintf(stderr,"\n ------------------------------------------- \n\n");
       lkey(&Lclt,&T,1,"%d",&T.departement); 	/* definition  d'1 cle complexe sur le departement   */
       lkey(&Lclt,&T,2,"%h",&T.age); 		    /* definition d'1 cle complexe sur l'age             */
       lkey(&Lclt,&T,3,"%1c",&T.sexe); 	  	    /* definition d'1 cle complexe sur le sexe           */
       lkey(&Lclt,&T,4,"%h",&T.cadeau); 	    /* definition d'1 cle complexe sur les cadeaux       */
       lkey(&Lclt,&T,5,"%1c %h",&T.sexe,&T.age);/* definition  d'1 cle complexe sur le sexe et l'age */
       /* c'est la derniere cle declare qui est valide ICI la 5 */
       UnSetBKey(&Lclt); 			 /* inhibe la cle complexe on revient sur la cle du initlist soit LLONG = numclient */
       lsort(&Lclt); 				 /* tri de la liste sur numclient */
       fprintf(stderr,"\n AFFICHE LA LISTE DES CLIENTS TRIES NUMCLIENT \n");
       walk_FLD(&Lclt,affclt); /* affiche la liste des clients tries */
       fprintf(stderr,"\n --------------------------------------------- \n\n");
 
       affiche_liste_client(1," DEPARTEMENT");
       affiche_liste_client(2," AGE ");
       affiche_liste_client(3," SEXE ");
       affiche_liste_client(4," CADEAU ");
       affiche_liste_client(5," SEXE et AGE ");
      /* faire un cadeau pour les clientes !! */
       walk_FLD(&Lclt,cadeauxclt);
       STRINIT(T);
       T.sexe = 'F';				/* on recherche que les femmes !!   */
       SetBKey(&Lclt,3); 			/* prendre la cle sur le champ sexe */
       fprintf(stderr,"\n --- LISTE CLIENTE(S) POUR CADEAU ------------ \n\n");
       walk_sameD(&Lclt,&T,affclt);
  
       close_list(&Lclt);
     }
     else
        fprintf(stderr,"\n ERREUR CREATION ");
}

  
/*
------------------------------------------------------------------------------
void charge_list(LLIST **l) : charge la liste avec le tableau clt[]
------------------------------------------------------------------------------
*/
void charge_list(LLIST **l)
{
  int i;
 for(i=0 ; clt[i].numclient ; i++)
     adjq(l,&clt[i]);
 fprintf(stderr,"\n chargement de %d client(s)",lgrl(l));
}

  
/*
------------------------------------------------------------------------------
int affclt(void *d) : affiche les infos du client
------------------------------------------------------------------------------
*/
int affclt(void *d)
{
   CLT *c=(CLT *)d;
 fprintf(stderr,"\n- Client:%ld departement:%2d age:%2hd sexe:%c cadeau:%hd",c->numclient
     ,c->departement
     ,c->age
     ,c->sexe
     ,c->cadeau);
   return(LOK);          /* permet le passage au suivant */
}
/*
------------------------------------------------------------------------------
void affiche_liste_client: affiche la liste des clients pour une cle
------------------------------------------------------------------------------
*/
void affiche_liste_client(int numclef,char *txt)
{
 SetBKey(&Lclt,numclef); /* on passe sur la cle complexe */
 lsort(&Lclt);           /* faire un tri : sur la cle 1: sur departement */
 fprintf(stderr,"\n -------------------------------------------------");
 fprintf(stderr,"\n - AFFICHE LA LISTE DES CLIENTS TRIES PAR %s ",txt);
 fprintf(stderr,"\n -------------------------------------------------");
 walk_FLD(&Lclt,affclt); /* affiche la liste des clients tries */
 fprintf(stderr,"\n ------------------------------------------------");
}
/*
------------------------------------------------------------------------------
int cadeauxclt(void *d) :
------------------------------------------------------------------------------
*/
int cadeauxclt(void *d)
{
 CLT *c=(CLT *)d;
 if( c->sexe == 'F' )
     c->cadeau = OUI;
 else
     c->cadeau = NON;
return(LOK);
}

fichier ZIP lkey.c