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
|
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
struct account{
char acctnum[5], actname[30];
char pin[4];
float intbal;
}bank;
//void item();
int main()
{ char again;
int success = 0;
char newnum[5], newname[30];
char npin[4];
float nbal;
FILE *fp, *fa;
fp = fopen("Accounts.txt","w");
printf("\n\nEnter account number:\t");
scanf("\n");
gets(bank.acctnum);
printf("Enter account name:\t");
scanf("\n");
gets(bank.actname);
printf("Enter Pin:\t");
scanf("\n");
gets(bank.pin);
printf("Enter Initial Balance:\t");
scanf("%f", &bank.intbal);
printf("\n\nCreate another account? [Yes/No]:\t");
scanf(" %c", &again);
fprintf(fp," \n\nEnter account number:\t%.5s \nEnter account name:\t%s \nEnter Pin:\t%s \nEnter Initial Balance:\t%.2f", bank.acctnum, bank.actname, bank.pin, bank.intbal);
fclose(fp);
do{
printf("\n\nAccount Number: ");
scanf(" \n");
gets(newnum);
fp = fopen("Accounts.txt","r");
fa = fopen("tempacct.txt", "w");
while (fscanf(fp,"%s%s%s%f", bank.acctnum, bank.actname, bank.pin, &bank.intbal)!=EOF) {
if(strcmp(newnum,bank.acctnum)==0)//if code is same
{
printf("Enter account name:\t");
scanf("\n");
gets(newname);
printf("Enter Pin:\t");
scanf("\n");
gets(npin);
success = 0;
printf("Enter Initial Balance:\t");
scanf("%f", &nbal);
getch();
success = 1;}
// end of if newcode the same
else
{
fprintf(fa,"%s%s%s%f", bank.acctnum, bank.actname, bank.pin, &bank.intbal);
}
}
fclose (fp);
fclose (fa);
remove("Products.txt");
rename("temproducts.txt","Products.txt");
if (success==0)
{ printf("Already Exist!"); }
getch();
printf("\n\nCreate More? [Y/N]: ");
scanf(" %c", &again);
}while(toupper(again)=='Y');
getch();
success = 0;
getch();
}
|