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
| void ajouter_client(void) {
client cl;
cl.cl_sj=0;
char oui='n';
FILE *cli=NULL;
date d;
getDate(&d);
putchar('\n');
cli=fopen("client.dat","rb+");
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); // position à la fin du fichier
fseek(cli,-sizeof(client),SEEK_CUR); // se déplacer d'une structure en arrière à partir de la position courante
fread(&cl,sizeof(client),1,cli); // lire la structure
fseek(cli,sizeof(client),SEEK_CUR);
do {
/*incrémenter le numéro du client*/
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);
} |