Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] web/email now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as C by registered user raphael ( 1 year ago )
#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

static struct livre* premier;
static struct livre* fin;
static struct livre *l1;
static struct livre *l2;
static struct livre *l3;
static struct livre *l4;
static struct livre *l5;

struct livre{
    char* titre;
    char* auteur;
    short int age;
    struct livre * suivant;
}__attribute__((packed));

void increment_element(struct livre* elem){
    *elem=*elem->suivant;
}

void ajout(struct livre* s){
    if(premier==NULL){
        premier=s;
        fin = premier;
        return;
    }
    fin->suivant = s;
    fin = s;

}
void main(int argc, char *argv[]){

    //struct livre l1 = {"Le bruit et la fureur", "William Faulkner", 1, NULL};
    l1 = malloc(sizeof(struct livre));
    l1->titre = "Le bruit et la fureur";
    l1->auteur = "William Faulkner";
    l1->suivant = NULL;
    //struct livre l2 = {"Demande à la poussière", "John Fante", 1, NULL};
    l2 = malloc(sizeof(struct livre));
    l2->titre = "Demande à la poussière";
    l2->auteur = "John Fante";
    l2->suivant = NULL;
    //struct livre l3 = {"À la recherche du temps perdu", "Albert Camus", 1, NULL};
    l3 = malloc(sizeof(struct livre));
    l3->titre = "À la recherche du temps perdu";
    l3->auteur = "Albert Camus";
    l3->suivant = NULL;
    //struct livre l4 = {"Madame Bovary", "Gustave Flaubert", 1, NULL};
    l4 = malloc(sizeof(struct livre));
    l4->titre = "Madame Bovary";
    l4->auteur = "Gustave Flaubert";
    l4->suivant = NULL;
    //struct livre l5 = {"La Divine Comédie", "Léon Tolstoï", 1, NULL};
    l5 = malloc(sizeof(struct livre));
    l5->titre = "La Divine Comédie";
    l5->auteur = "Léon Tolstoï";
    l5->suivant = NULL;

    premier = NULL;
    fin = premier;
    ajout(&*l3);
    ajout(&*l5);
    ajout(&*l4);
    ajout(&*l2);
    ajout(&*l1);

    struct livre* elem = malloc(sizeof(struct livre));
    elem = premier;
    printf("Voici la liste chainée trié par ordre alphabétique par noms d'auteurs des livres de la bibliotheque :\n\n");
    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);
    return;
}

 

Revise this Paste

Your Name: Code Language: