i have here 2 program the first one #include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<process.h>
struct record{
char acc_name[6];
int pin;
float bal;
};
void main()
{
FILE *fp;
struct record b;
clrscr();
if((fp=open("accounts.dat","wt"))==0)
{
printf("Error");
exit(1);
}
printf("Enter account name:");
gets(b.acc_name);
printf("Enter account pin:");
scanf("%d",&b.pin);
printf("Enter balance:");
scanf("%f",&b.bal);
fprintf(fp,"%s %d %.2f",b.acc_name,b.pin,b.bal);
fclose(fp);
}
it lets user enter data and eventuallly store them in .dat file. this is a file handling in binary mode.
and the other one is this
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<process.h>
#include<dos.h>
void main()
{
FILE *fp;
char key,opt,ex,acc_name,x,y,z;
float amt_dep,amt_with,bal;
int pin;
fp=fopen("accounts.dat","r");
if(fp==NULL)
{
printf("Error");
exit(1);
}
clrscr();
printf("Account name:");
scanf("%s",&acc_name);
while(&fread(&b,sizeof(record),1,fp)!=NULL)
{b.acc_name=x;
if(acc_name=x)
{
printf("account name accepted!");
}
else{printf("invalid account!");}
}}
printf("Enter PIN:");
scanf("%d",&pin);
while(&fread(&b,sizeof(record),1,fp)!=NULL)
{printf("access granted!");
goto menu_dep;
}
else{
printf("Access denied!");}
menu:
{
printf("[1] balance inquiry");
printf("[2] deposit");
printf("[3] withdraw");
opt=getche();
}
switch(opt);
{
case '1':
{
clrscr();
printf("balance inquiry");
while(&fread(&b,sizeof(record),1,fp)!=NULL)
printf("your current balance is:%.2f",b.bal);
printf("another transaction?([y]/n)");
ch=getch();
if(ch=='Y'||ch=='y')
{
goto menu;
}
clrscr();
{
case '2':
clrscr();
printf("amount to deposit:P");
scanf("%f",&amt_dep);
while(&fread(&b,sizeof(record),1,fp)!=NULL)
{
b.bal=z;
z=amt_dep+z;
printf("your balance now is P%.2f",z);}
printf("another transaction?([y]/n)");
ch=getch();
if(ch=='Y'||ch=='y')
{
goto menu;
}
clrscr();
}
case'3':
{clrscr("amount to withdraw: P");
scanf("%f"&amt_with);
while(&fread(&b,sizeof(record),1,fp)!=NULL)
z=z-amt_with;
if(amt_with>z)
{
printf("Isuficient balance!");
}
else{printf("thank you! ");}
printf("another transaction?([y]/n)");
ch=getch();
if(ch=='Y'||ch=='y')
{
goto menu;
}
clrscr();
}
fclose(fp);
}
it is the atm program, it lets user input an account name if the account name did not match in the data yuo have previously typed in the first program it displays invalid account. my problem now is how can i match the data i input in the second program in the data stored in the first program. pls help me. i need this on wednesday.
and we only use the printf scanf version not the cin and cout.thank you!!