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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
| #define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <string.h>
// Structures
struct chantiers
{
long Numchantier;
char NomChantier [25] ;
char rue [50] ;
int CodePostal ;
char ville [20] ;
char MaîtreOuvrage[30] ;
float Montant ;
int Durée ;
char Gérant [3] ;
int position ;
} ;
struct date
{
short Jour;
short Mois;
short Annee;
} ;
struct ouvriers
{
long NumRegistre ;
char Nom [25] ;
char Prenom[30] ;
char Rue [50] ;
int CodePostal ;
char Ville [20] ;
char Specialite [20] ;
struct date d_engag ;
struct date d_naiss ;
} ;
// Prototypes
void Menu();
void Init_Ouvriers(char *);
void Init_Chantiers(char *);
// Fonction principale
void main()
{
int indice = 0, fini=0;
char nom_ouvrier[25] = "Ouvriers.dat";
char nom_chantier[25]= "Chantiers.dat";
while (fini == 0)
{
Menu();
fflush(stdin);
scanf("%d",&indice);
switch(indice)
{
case 1:
system("CLS");
Init_Ouvriers(nom_ouvrier);
Init_Chantiers(nom_chantier);
break;
case 2:
system("CLS");
nom_ouvrier[0] = '\0';
printf("Entrer le nom du fichier Ouvriers (avec l extension .dat): ");
scanf("%s", &nom_ouvrier);
printf("\n");
printf("Entrer le nom du fichier Chantiers (avec l extension .dat): ");
scanf("%s", &nom_chantier);
Init_Ouvriers(nom_ouvrier);
Init_Chantiers(nom_chantier);
break;
case 3:
fini = 1;
break;
default:
system("CLS");
printf("Veuillez ne pas rentrer n'importe quoi .. \n");
Sleep(1500);
system("CLS");
break;
}
}
}
// Fonction Menu
void Menu()
{
system("CLS");
printf("Bienvenue dans ce programme de bidonnage\n");
printf("Que voulez-vous faire?\n");
printf("1. Utiliser les fichiers par default\n");
printf("2. Utilisez d'autres fichiers\n");
printf("3. Quitter le programme\n");
printf("Votre choix: ");
}
// Fonction qui cree le bidonnage du fichier ouvriers
void Init_Ouvriers(char *Fichier_Ouvriers)
{
FILE *f_file;
int i, reponse, fini = 0;
struct ouvriers pouvrier;
while (fini == 0)
{
f_file = fopen(Fichier_Ouvriers,"rb");
if (f_file != NULL)
{
//fclose(f_file);
printf("Le fichier %s existe deja\n",Fichier_Ouvriers);
printf("Que voulez-vous faire?\n");
printf("1. Supprimer et remplacer\n");
printf("2. Ne pas le suprpimer\n");
printf("Votre choix: ");
fflush(stdin);
scanf("%d",&reponse);
}
else
{
// fclose(f_file);
reponse = 1;
}
fclose(f_file);
switch (reponse)
{
case 1:
// Initialisation de table ouvrier
for(i = 0; i < 100; i++)
{
pouvrier.NumRegistre = -1;
pouvrier.Nom[0] = '\0';
pouvrier.Prenom[0] = '\0';
pouvrier.Rue[0] = '\0';
pouvrier.CodePostal = 0;
pouvrier.Ville[0] = '\0';
pouvrier.Specialite[0] = '\0';
pouvrier.d_engag.Jour = 0;
pouvrier.d_engag.Mois = 0;
pouvrier.d_engag.Annee = 0;
pouvrier.d_naiss.Jour = 0;
pouvrier.d_naiss.Mois = 0;
pouvrier.d_naiss.Annee = 0;
}
f_file = fopen(Fichier_Ouvriers,"wb");
if (f_file == NULL)
{
perror("Probleme lors de l ouverture du fichier ouvrier\n");
}
else
{
for (i=0 ; i<100; i++)
fwrite(&pouvrier, sizeof(struct ouvriers),1 , f_file);
}
fclose(f_file);
system("CLS");
printf("Bidonnage du fichier %s effectue",Fichier_Ouvriers);
Sleep(1500);
fini = 1;
break;
case 2:
fini = 1;
break;
default:
fini = 0;
system("CLS");
printf("Ne rentrer pas n'importe quoi ...");
Sleep(1500);
system("CLS");
break;
}
}
}
// Fonction qui crée le bidonnage du fichier chantiers
void Init_Chantiers(char *Fichier_Chantier)
{
int i, reponse, fini = 0;
FILE *f_file;
struct chantiers pchantier;
while (fini == 0)
{
system("CLS");
f_file = fopen(Fichier_Chantier,"rb");
if (f_file != NULL)
{
//fclose(f_file);
printf("Le fichier %s existe deja\n",Fichier_Chantier);
printf("Que voulez-vous faire?\n");
printf("1. Supprimer et remplacer\n");
printf("2. Ne pas le suprpimer\n");
printf("Votre choix: ");
fflush(stdin);
scanf("%d",&reponse);
}
else
{
//fclose(f_file);
reponse = 1;
}
fclose(f_file);
switch (reponse)
{
case 1:
for(i = 0; i<20; i++)
{
pchantier.Numchantier = -1;
pchantier.NomChantier[0] = '\0';
pchantier.rue[0] = '\0';
pchantier.CodePostal = 0;
pchantier.ville[0] = '\0';
pchantier.MaîtreOuvrage[0] = '\0';
pchantier.Montant = 0;
pchantier.Durée = 0;
pchantier.Gérant[0] = '\0';
pchantier.position = 0;
}
f_file = fopen(Fichier_Chantier,"wb");
if (f_file == NULL)
{
perror("Probleme lors de l ouverture du fichier chantier\n");
}
else
{
for (i=0 ; i< 20 ; i++)
fwrite(&pchantier, sizeof(struct chantiers),1 , f_file);
}
fclose(f_file);
system("CLS");
printf("Bidonnage du fichier %s effectue",Fichier_Chantier);
Sleep(1500);
fini = 1;
break;
case 2:
fini = 1;
break;
default:
system("CLS");
printf("Ne rentrer pas n'importe quoi ...");
Sleep(1500);
system("CLS");
fini = 0;
break;
}
}
} |
Partager