1 2 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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
char titre[46];
char auteur[21];
char genre[21];
char dateDeParution[11];
struct livre *suivant;
}livre;
main()
{
int choix,nb=0,i;
char variable[50]={0.};
livre *debut,*suivant,*encourt;
FILE *fdat,*fdat2;
fdat2 = fopen("bibliotheque.dat","w");
fdat = fopen("bibliotheque.dat","r");
debut = malloc(sizeof(livre));
encourt = debut;
fscanf(fdat,"%s%s%s%s",encourt->titre,encourt->auteur,encourt->genre,encourt->dateDeParution);
while(!feof(fdat))
{
suivant = malloc(sizeof(livre));
encourt->suivant = suivant;
encourt = suivant;
fscanf(fdat,"%s%s%s%s",encourt->titre,encourt->auteur,encourt->genre,encourt->dateDeParution);
}
printf("Programme de bibliothèque de livre");
do
{
printf("1. Afficher liste\n");
printf("2. Rechercher un élément\n");
printf("3. Ajouter un élément\n");
printf("4. Supprimer un élément\n");
printf("5. Quitter le programme\n");
printf("votre choix :");
scanf("%1d",&choix);
if(choix == 1)
{
printf("affichage des elements\n");
encourt=debut;
for(i=0;i<nb;i++)
{
printf("%-25s \n%-20s \n%-20s \n%-8s",encourt->titre,encourt->auteur,encourt->genre,encourt->dateDeParution);
encourt = encourt->suivant;
}
}
if(choix == 2)
{
printf("recherche d'un element\n");
}
if(choix == 3)
{
printf("ajout d'elements\n");
if(nb==0)
{
debut = malloc(sizeof(livre));
encourt = debut;
printf("Entrez le titre du livre :");
//sensé éliminer le \n
getchar();
gets(encourt->titre);
printf("Entrez le nom de l'auteur :");
gets(encourt->auteur);
printf("Entrez le genre :");
gets(encourt->genre);
printf("Encodez la date de parution(jj/mm/aaaa) :");
gets(encourt->dateDeParution);
fprintf(fdat2,"%-45s %-20s %-20s %-8s",encourt->titre,encourt->auteur,encourt->genre,encourt->dateDeParution);
nb++;
encourt->suivant = NULL;
}
}
if(choix == 4)
{
printf("suppression d'un element\n");
}
}while(choix !=5);
printf("fin de l'application");
} |
Partager