-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
164 lines (155 loc) · 4.88 KB
/
main.c
File metadata and controls
164 lines (155 loc) · 4.88 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char titre[100][100];
char auteur[100][100];
int quantite[100];
float prix[100];
char livreRechercher[100];
int compteur = 0;
//fonction d'ajouter des livre
void ajouter(){
int choix;
printf("Entrer les informations suivantes : \n");
printf("Titre de Livre : ");
fgets(titre[compteur], 100, stdin);
titre[compteur][strcspn(titre[compteur], "\n")] = '\0';
printf("Auteur : ");
fgets(auteur[compteur], 100, stdin);
auteur[compteur][strcspn(auteur[compteur], "\n")] = '\0';
printf("Qantite a stoquer : ");
scanf("%d", &quantite[compteur]);
printf("Prix de Livre : ");
scanf("%f", &prix[compteur]);
compteur++;
/* if (compteur=100) {
printf("Pas de place pour stocker ce livre.");
} */
}
//Fonction d'afficher les detailles de livre.
void afficher(){
for (int i=0; i<compteur; i++){
printf("\n\t********\n");
printf("Information de Livre %d\n", i+1);
printf("Titre de livre : %s\n", titre[i]);
printf("auteur : %s\n", auteur[i]);
printf("Quantite disponible : %d\n", quantite[i]);
printf("Prix : %.2f\n", prix[i]);
printf("\n\t********\n");
}
}
void details(){
int status, existe;
printf("Entrer le titre de livre a modifier : \n");
fgets(livreRechercher, 100, stdin);
livreRechercher[strcspn(livreRechercher, "\n")] = '\0';
for (int i=0; i<compteur; i++){
existe = 0;
status = strcmp(titre[i], livreRechercher);
if (!status){
existe = 1;
printf("Information de Livre rechercher :\n");
printf("Titre de livre : %s\n", titre[i]);
printf("auteur : %s\n", auteur[i]);
printf("Quantite disponible : %d\n", quantite[i]);
printf("Prix : %.2f\n", prix[i]);
break;
}
}
if (existe == 0){
printf("Livre n'existe pas dans le stcks.\n");
}
}
//Fonction pour modifier la quantite d'un Livre
void modifier(){
int status, existe;
printf("Entrer le titre de livre a modifier : \n");
fgets(livreRechercher, 100, stdin);
livreRechercher[strcspn(livreRechercher, "\n")] = '\0';
for (int i=0; i<compteur; i++){
existe = 0;
status = strcmp(titre[i], livreRechercher);
if (!status){
existe = 1;
printf("Entrer la nouvelle quantite : ");
scanf("%d", &quantite[i]);
printf("La Quantite est Bien modifier.");
break;
}
}
if(existe == 0){
printf("Pas de livre avec ce titre, Essayer de le ajouter.");
}
}
//Fonction pour supprimer Un livre
void supprimer(){
char search_livre[100];
int position;
printf("Entrer le titre de Livre a suprimer : ");
fgets(search_livre, 100, stdin);
search_livre[strcspn(search_livre, "\n")] = '\0';
//int status = strcmp(search_livre, titre[100])
for(int i=0; i<compteur; i++){
if (strcmp(search_livre, titre[i]) == 0){
position = i;
break;
}
}
for (int i = position; i<compteur-1; i++){
strcpy(titre[i], titre[i+1]);
}
printf("Le livre est bien supprimer.");
compteur--;
}
void lister(){
int somme = 0;
for (int i=0; i<compteur; i++){
somme = somme + quantite[i];
}
printf("Le nombre totale de livre est %d", somme);
}
int main(){
int option;
do {
printf("\n-------------------------------------------------------------------------\n");
printf("\t\t\tMenu d'opperation possible :\n");
printf("1. Ajouter un livre au stock.\n");
printf("2. Afficher tous les livres disponibles.\n");
printf("3. Rechercher un livre par son titre.\n");
printf("4. Mettre a jour la quantite d'un livre.\n");
printf("5. Supprimer un livre du stock.\n");
printf("6. Afficher le nombre total de livres en stock.\n");
printf("7. Entrer 7 pour quiter le programme.\n");
printf("\n---------------------------------------------------------------------\n");
printf("Entrer votre choix : ");
scanf("%d", &option);
char buffer;
scanf("%c", &buffer);
switch(option){
case 1:
ajouter();
break;
case 2:
afficher();
break;
case 3:
details();
break;
case 4:
modifier();
break;
case 5:
supprimer();
break;
case 6:
lister();
break;
case 7:
break;
default :
printf("L'operation souhaiter n'existe pas.");
}
}while(option != 7);
system("pause");
return 0;
}