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
| #include<stdio.h>
#include<string.h>
/*structure modélisant un livre constituée de :
o Un nom (30 caractères)
o Un auteur (20 caractères)
o Un ISBN (entier représentant lidentifiant du livre)*/
typedef struct livre{
char nom[31];
char auteur[21];
int isbn;
}LIVRE;
/*structure modélisant une bibliothèque constituée de :
o Un nom (50 caractères)
o Un tableau de pointeurs statique de 1000 livres.
o Que faut-il dautres comme informations ?*/
typedef struct bibliotheque{
char nom[51];
LIVRE* livres[1000];
int nbrlivres;
}BIBLIO;
/* Fonction de recherche d'un bibliothèque*/
/*return NULL si la bibli n'est pas trouvé*/
/*Sinon return l'adresse de la bibliothèque*/
BIBLIO* rechercheBiblio(char nom[],BIBLIO tab[]){
int i;
for(i=0;i<5;i++){
if(strcmp(tab[i].nom,nom)==0)return &tab[i];
}
return NULL;
}
void add_livre(BIBLIO tab[]){
char nom[51];
LIVRE bouquin;
printf("Bibliotheque ou ajouter le livre\n");
scanf("%s",nom);
if(rechercheBiblio(nom,tab)==NULL){
printf("Desole la bibliothèque n'existe pas\n");
return;
}else{
printf("nom du bouquin ?");
scanf("%s",&bouquin.nom);
printf("auteur ?");
scanf("%s",&bouquin.auteur);
printf("ISBN ?");
scanf("%d",&bouquin.isbn);
rechercheBiblio(nom,tab)->livres[rechercheBiblio(nom,tab)->nbrlivres]=&bouquin;
/*printf("%d",rechercheBiblio(nom,tab)->livres[rechercheBiblio(nom,tab)->nbrlivres]->isbn);*/
rechercheBiblio(nom,tab)->nbrlivres ++;
}
}
/*fonction listant les livres présents dans une bibliothèque.*/
void liste_livres(char nom[],BIBLIO tab[]){
int i;
if (rechercheBiblio(nom,tab)->nbrlivres==0) {
printf("la bibliotheque est vide");
return;
}
printf("La bibli contient les livres :\n");
printf("%s\n",tab[0].livres[0]->nom);
/*for(i=0;i<2;i++){
printf("%s\n",&(tab[0]).livres[i]->nom);
}*/
}
int main(){
BIBLIO tab[4];
BIBLIO test1;
LIVRE temp;
char nom[51];
test1.nbrlivres=0;
strcpy(test1.nom,"biblii");
tab[0]=test1;
add_livre(tab);
strcpy(nom,"biblii");
printf("\n");
printf("%d",rechercheBiblio(nom,tab)->livres[rechercheBiblio(nom,tab)->nbrlivres]->isbn);
liste_livres(nom,tab);
system("pause");
return 0;
} |
Partager