-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojet.c
More file actions
137 lines (115 loc) · 3.39 KB
/
projet.c
File metadata and controls
137 lines (115 loc) · 3.39 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
#include <stdio.h>
#include <stdlib.h>
struct client{
char numClient[50];
char nom[100];
};
struct materiel{
char numMat[25];
char nom[50];
char disign[100];
int pu;
double StockActuel;
double StockInit;
};
struct achat{
char numClient[50];
char numMat[100];
int qte;
char dateAchat[50];// atao struct ny date
};
void creation_Fmateriel();
int ajout_mat();
int recherch_mat(char);
int main()
{
system("color a");
system("cls");
char nb[20],a,b; int choi;
printf("--------MENU--------\n");
printf("1---Ajout du materiel---\n");
printf("2---Recherche du materiel---\n");
printf("3---Quitter");
printf("\t\t\tVotre choix svp: ");scanf("%d",&choi);
switch(choi){
case 1:{
ajout_mat();
printf("Quitter ou rester(Q\\R)");scanf("%s",&a);
if(a == 'Q' || a == 'q') return 2;
main();}
break;
case 2: {
printf("Entrer le numero ou le nom du materiel a chercher :");scanf("%s5",nb);
recherch_mat(*nb);
printf("\n\tQuitter ou rester (Q\\R)");scanf("%s",&b);
if(b == 'Q' || b == 'q') return 2;
main();
}break;
case 3: return 2;
default : printf("Mauvaise touche ..."); main();
}
creation_Fmateriel();
return 0;
}
void creation_Fmateriel(){
FILE *file = fopen("Materiel.txt","a");
fclose(file);
}
/*
void creation_Fclient(){
FILE *file = fopen("client.txt","w");
fclose(file);
}
*/
int recherch_mat(char numMatrl){
struct materiel rech;
FILE *file = NULL;
file = fopen("Materiel.txt","r");
do{
fscanf(file,"%s\t%s\t\t%s\n",rech.numMat,rech.nom,rech.disign);
fflush(stdin);
if(numMatrl == *rech.numMat || numMatrl == *rech.nom){
printf("\nNumero: %s\nNom: %s\nPrix unitaire: %s\n",rech.numMat,rech.nom,rech.disign);
return 1;
}
}while(!feof(file));
printf("Le materiel n'existe pas \n");// si non le materiel n'existe pas
fclose(file);
return 0;
}
int ajout_mat(){
struct materiel mat;
int ajout; char chaine;
FILE *file = NULL;
printf("Entrer le numero du materiel: ");scanf("%s",mat.numMat);
printf("Entrer le nom du materiel: ");scanf("%s",mat.nom);
printf("Le taux de la materiel: ");scanf("%d",&mat.pu);
ajout = recherch_mat(*mat.numMat);
if(ajout == 0)
{
file = fopen("Materiel.txt","r");
chaine = fgetc(file);
fflush(stdin);
if(chaine == 'N')
{
fclose(file);
file = fopen("Materiel.txt","a");
fprintf(file,"%s\t%s\t\t%d\n",mat.numMat,mat.nom,mat.pu);
fclose(file);
return -1;
}
else
{
fclose(file);
file = fopen("Materiel.txt","a");
fprintf(file,"Numero\tNOM\t\tTaux\n");
fprintf(file,"%s\t%s\t\t%d\n",mat.numMat,mat.nom,mat.pu);
fclose(file);
return -2;
}
}
else{
printf("\nLe materiel deja saisi\n");
}
return 1;
}