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
|
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
char rue[50]; // rue
char cp[10]; // code postal
char loc[30]; // localite
char pays[20]; // pays
}
adresse;
typedef struct
{
char cl_nom[30]; // nom du client
char cl_prenom[30]; // prenom du lient
adresse cl_adresse; // adresse du client
char cl_tel[20]; // numero de telephone fixe du client
char cl_tel2[20]; // numero de telephone portable du client
char cl_email[50]; // Email du client
int cl_sj; // n° du dernier sejour du client 0==neant
}
client;
int main (void) {
client cl;
cl.cl_sj=0;
char oui='n';
FILE *cli=NULL;
cli=fopen("client.dat","rb"); // ici
if(cli == NULL) {
cli=fopen("client.dat","wb");
do {
cl.cl_sj=cl.cl_sj+1;
printf("Client N ° %d \n",cl.cl_sj);
printf("Votre nom : ");
scanf("%s",cl.cl_nom);
printf("Votre prenom : ");
scanf("%s",cl.cl_prenom);
printf("Votre rue : ");
scanf("%s",cl.cl_adresse.rue);
printf("Votre code postal : ");
scanf("%s",cl.cl_adresse.cp);
printf("Votre localite : ");
scanf("%s",cl.cl_adresse.loc);
printf("votre pays : ");
scanf("%s",cl.cl_adresse.pays);
printf("Telephone fixe : ");
scanf("%s",cl.cl_tel);
printf("Telephone portable : ");
scanf("%s",cl.cl_tel2);
printf("Email : ");
scanf("%s",cl.cl_email);
fwrite(&cl,sizeof(client),1, cli);
puts("Donnee rentree avec succes");
getchar();
do {
printf("Voulez-vous entrer un nouveau client ? o/n ");
scanf("%c",&oui);
}while(oui != 'n' && oui != 'o');
}while(oui == 'o' || oui == 'O');
}
else {
fseek(cli,0,SEEK_END);
fseek(cli,-sizeof(client),SEEK_CUR);
fread(&cl,sizeof(client),1,cli);
fseek(cli,sizeof(client),SEEK_CUR);
do {
cl.cl_sj=cl.cl_sj+1;
printf("Client N ° %d \n",cl.cl_sj);
printf("Votre nom : ");
scanf("%s",cl.cl_nom);
printf("Votre prenom : ");
scanf("%s",cl.cl_prenom);
printf("Votre rue : ");
scanf("%s",cl.cl_adresse.rue);
printf("Votre code postal : ");
scanf("%s",cl.cl_adresse.cp);
printf("Votre localite : ");
scanf("%s",cl.cl_adresse.loc);
printf("votre pays : ");
scanf("%s",cl.cl_adresse.pays);
printf("Telephone fixe : ");
scanf("%s",cl.cl_tel);
printf("Telephone portable : ");
scanf("%s",cl.cl_tel2);
printf("Email : ");
scanf("%s",cl.cl_email);
fwrite(&cl,sizeof(client),1, cli);
puts("Donnee rentree avec succes");
getchar();
do {
printf("Voulez-vous entrer un nouveau client ? o/n ");
scanf("%c",&oui);
}while(oui != 'n' && oui != 'o');
}while(oui == 'o' || oui == 'O');
}
fclose(cli);
return EXIT_SUCCESS;
} |
Partager