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
|
#include <stdio.h>
#include <conio.h>
#include <string.h>
#define cliente "E:\\TC\BIN\projet.TXT"
typedef struct
{
char nom;
char prenom;
int num_compte;
int mot_de_passe;
float solde;
}
fiche; /* creation d'un type fiche client*/
void saisie_compte( int *n)
{clrscr();
do
{
printf("ENTREZ VOTRE NUMERO DE COMPTE \n\n");
scanf("%d",&n);
flushall();
}
while(n<0);
}
void verifier_ncompte(int ncompte,int *trouve,FILE *f)
{ char choix; int compteur=0;
fiche client;trouve=0;
clrscr();
f = fopen(cliente,"r");
while((fread(&client,sizeof(fiche),1,f)!=0)&&(client.num_compte!=ncompte))
{
if (client.num_compte!=ncompte)
compteur++;
}
if (client.num_compte==ncompte)
*trouve=1;
}
void saisie_mot_passe(int *n)
{
clrscr();
do
{
printf("ENTREZ VOTRE NUMERO DE PASSE \n\n");
scanf("%d",&n);
flushall();
}
while(n<0);
}
void verifier_mot_passe(int mot_passe,int ncompte,int *existe,FILE *f)
{ char choix; int compteur=1 ;
fiche client; existe=0;
clrscr();
f = fopen(cliente,"r");
while((fread(&client,sizeof(fiche),1,f)!=0)&&((client.num_compte!=ncompte) || (client.mot_de_passe!=mot_passe)))
{
if (client.mot_de_passe!=mot_passe)
compteur++;
}
if (client.mot_de_passe==mot_passe)
*existe=1;
}
void aff_menu()
{ clrscr();
printf("\t\t\tMENU COMPTE CLIENT\n");
printf("\t\t\t ------------------\n\n\n");
printf("RETRAIT ---> 1\n");
printf("SOLDE DU COMPTE ---> 2\n");
printf("DERNIERS MOUVEMENTS ---> 3\n");
printf("VIREMENT D'UNE CERTAINE SOMME D'ARGENT D'COMPTE A UN AUTRE ---> 4\n");
printf("...........RESTE DU MENU......... ---> 4\n");
printf("SORTIE ---> S\n\n");
}
void retrait ( int ncompte,FILE *f)
{
fiche client;
float m;
int compteur=0;
clrscr();
f = fopen(cliente,"r");
printf("ENTREZ LE MONTANT: ");
scanf("%f",&m);
flushall();
while ((fread(&client,sizeof(fiche),1,f)!=0)&& ( client.num_compte!=ncompte ))
compteur++;
if (client.solde>= m )
{
client.solde= client.solde - m;
fseek(f,compteur,SEEK_SET);
fwrite(&client,sizeof(fiche),1,f);
printf("Operations effectuee Avec Succee: ");
}
else
printf("Solde insuffisant Pour Effectuer cette Operations: ");
fclose(f);
}
void solde_du_compte( int ncompte,FILE *f)
{
fiche client;
int compteur=0;
clrscr();
f = fopen(cliente,"r");
while ((fread(&client,sizeof(fiche),1,f)!=0)&& ( client.num_compte!=ncompte ))
compteur++;
if (client.num_compte==ncompte );
printf("SOLDE: ",client.solde);
fclose(f);
}
void vir_compte_compte( int ncompte,FILE *f)
{
fiche client;
int trouve;
int deuxieme_num_compte,m;
int compteur,compteur1;
compteur=0;
compteur1=0;
clrscr();
f = fopen(cliente,"a");
do
{
printf("Entrez le deuxieme numero de compte: ");
scanf("%f",&deuxieme_num_compte);
flushall();
verifier_ncompte(deuxieme_num_compte,&trouve,f);
}
while (trouve!=1);
printf("Entrer le montant à transferer: ");
scanf("%f",&m);
flushall();
rewind(f);
while ((fread(&client,sizeof(fiche),1,f)!=0)&& ( client.num_compte!=ncompte ))
compteur++;
if (client.solde>= m )
{
client.solde= client.solde - m;
fseek(f,compteur,SEEK_SET);
fwrite(&client,sizeof(fiche),1,f);
rewind(f);
fread(&client,sizeof(fiche),1,f);
while ((fread(&client,sizeof(fiche),1,f)!=0)&& ( client.num_compte!=deuxieme_num_compte ))
compteur1++;
if( client.num_compte==deuxieme_num_compte );
client.solde=client.solde+m;
fseek(f,compteur,SEEK_SET);
fwrite(&client,sizeof(fiche),1,f);
printf("Operatios effectuée Avec Succée !: ");
}
else
printf("Solde insuffisant Pour Effectuer cette Operations: ");
fclose(f);
}
/*void aff( FILE *f)
{ char n;
fiche client;
int compteur=0;
clrscr();
printf("LECTURE DU FICHIER\n\n");
printf("NOM DU FICHIER A LIRE: ");gets(n);
flushall();
f = fopen(cliente,"r");
if (f == NULL) printf("\nERREUR, CE FICHIER N'EXISTE PAS\n\n");
else
{
printf("\nLISTING DU FICHIER\n\n");
while(fread(&client,sizeof(fiche),1,f)!=0)
{
printf("client n?%d: \n",compteur);
compteur++;
printf("%s %s \n %d\n %d\n %f \n",client.nom,client.prenom,client.num_compte,client.mot_de_passe,client.solde);
}
fclose(f);
}
printf("POUR CONTINUER FRAPPER UNE TOUCHE ");
getch();
}*/
void main()
{
FILE *fichier;
char nom[10]; /* nom du fichier */
char choix;
int mot_passe,ncompte,trouve,existe;
do
{
saisie_compte(&ncompte);
verifier_ncompte(ncompte,&trouve,fichier);
}
while (trouve==1);
do
{
saisie_mot_passe(&mot_passe);
verifier_mot_passe(mot_passe,ncompte,&existe,fichier);
}
while (existe==1);
do
{
aff_menu();
printf("VOTRE CHOIX: ");
choix = (char)getchar();
flushall();
switch(choix)
{
case '1':retrait(ncompte,fichier);break;
case '2':solde_du_compte(ncompte,fichier);break;
/*case '3':derniers_mvts(fichier,nom);break;*/
case '4':vir_compte_compte(ncompte,fichier);break;
/*case '5':Autre..reste de menu*/
/* case '6':aff(fichier);break;*/
}
}
while ((choix!='S') && (choix!='s'));
} |
Partager