-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbiblio.c
More file actions
118 lines (99 loc) · 2.07 KB
/
biblio.c
File metadata and controls
118 lines (99 loc) · 2.07 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "biblio.h"
void init(T_Bibliotheque *ptrB)
{
ptrB->nbLivres=0;
}
int ajouterLivre(T_Bibliotheque *ptrB)
{
if (ptrB->nbLivres<CAPACITE_BIBLIO)
{
saisirLivre(&(ptrB->etagere[ptrB->nbLivres]));
ptrB->nbLivres++;
return 1;
}
return 0;
}
int afficherBibliotheque(const T_Bibliotheque *ptrB) {
int i;
if(ptrB->nbLivres==0)
return 0;
else
{
for(i=0;i<ptrB->nbLivres;i++)
{
printf("%d- ",i);
afficherLivre( &(ptrB->etagere[i]) );
}
return 1;
}
}
int rechercherBibliotheque(T_Bibliotheque *ptrB)
{
int j, occurences=0;
char recherche[MAX];
if(ptrB->nbLivres==0)
{
return 0;
}
else
{
fgets(recherche, MAX, stdin);
recherche[strlen(recherche)-1]='\0';
for(j=0;j<ptrB->nbLivres;j++)
{
//printf("%d \n",(strcmp(recherche,(ptrB->etagere[j]).titre))); TEST DU STRCMP
if (strcmp(recherche,(ptrB->etagere[j]).titre)==0)
{
printf("%d - ", j);
afficherLivre( &(ptrB->etagere[j]) );
occurences++;
}
}
printf("Il y a %d",occurences);
printf(" occurences \n");
}
if (occurences==0) return 0;
else return 1;
}
int rechercheAuteur(T_Bibliotheque *ptrB)
{
int j, occurences=0;
char recherche[MAX];
if(ptrB->nbLivres==0)
return 0;
else
{
fgets(recherche, MAX, stdin);
recherche[strlen(recherche)-1]='\0';
for(j=0;j<ptrB->nbLivres;j++)
{
//printf("%d \n",(strcmp(recherche,(ptrB->etagere[j]).auteur)));
if (strcmp(recherche,(ptrB->etagere[j]).auteur)==0)
{
printf("%d - ", j);
afficherLivre( &(ptrB->etagere[j]) );
occurences++;
}
}
if (occurences==0) return 0;
else return 1;
}
}
int supprimerLivre(T_Bibliotheque *ptrB, int pos)
{
int i;
if (ptrB->nbLivres==0 || pos<0 || pos>(ptrB->nbLivres))
{
return 0;
}
else
{
enleverLivre(&(ptrB->etagere[pos]));
for(i=pos;i<(ptrB->nbLivres)-1;i++)
{
(ptrB->etagere[i])=(ptrB->etagere[i+1]);
}
ptrB->nbLivres=ptrB->nbLivres-1;
return 1;
}
}