#include <stdio.h>
#include <limits.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdarg.h>
//auteur : Raphael De Oliveira
struct livre{
char* titre;
char* auteur;
short int age;
struct livre * suivant;
}__attribute__((packed));
void increment_element(struct livre* elem){
*elem=*elem->suivant;
}
static struct livre* ajout(char * t, char* a, int y){
static struct livre* premier;
static struct livre* fin;
struct livre* s;
s = malloc(sizeof(struct livre));
s->titre = t;
s->auteur = a;
s->age = y;
s->suivant = NULL;
if(premier==NULL){
premier=s;
fin = premier;
return premier;
}
fin->suivant = s;
fin = s;
}
void affichage_bibliotheque(struct livre * elem){
while(elem->suivant!=NULL){
printf("%s | %s\n",elem->titre,elem->auteur);
//elem=elem->suivant;
increment_element(elem);
}
printf("%s| %s\n",elem->titre,elem->auteur);
}
void main(int argc, char *argv[]){
struct livre* elem = malloc(sizeof(struct livre));
elem = ajout("À la recherche du temps perdu","Albert Camus",10);
ajout("Madame Bovary", "Gustave Flaubert", 200);
ajout("Demande à la poussière", "John Fante", 12);
ajout("La Divine Comédie","Léon Tolstoï",30);
ajout("Le bruit et la fureur", "William Faulkner", 2);
printf("Voici la liste chainée trié par ordre alphabétique par noms d'auteurs des livres de la bibliotheque :\n\n");
affichage_bibliotheque(elem);
return;
}
Add a code snippet to your website: www.paste.org