You are on page 1of 2

EX.NO.

17-COUNTING ACCOUNTS WITH MINIMUM BALANCE-SEQUENTIAL ACCESS FILE


#include<stdio.h>
#define MINBAL 500
struct account
{
int accno;
char accname[25];
float balance;
};
int main()
{
struct account acc;
int choice,count;
FILE *fp;
do
{
printf("\n1.Add Account details");
printf("\n2.Display Account details");
printf("\n3.Count number of accounts with minimum balance");
printf("\n0.Exit");
printf("\nEnter choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
fp=fopen("Account1.dat","a");
//fseek(fp,0,2); //go to last position
printf("\nEnter Account number,name and balance");
scanf("%d %s %f",&acc.accno,&acc.accname,&acc.balance);
fwrite(&acc,sizeof(acc),1,fp);
fclose(fp);
break;
}
case 2:
{
fp=fopen("Account1.dat","r");
printf("\nAcc-no\tAcc-name\t\tBalance:\n");
while(fread(&acc,sizeof(acc),1,fp)==1)
{

printf("%d\t%s\t%.2f\n",acc.accno,acc.accname,acc.balance);
}
fclose(fp);
break;
}
case 3:
{
fp=fopen("Account1.dat","r");
count=0;
while(fread(&acc,sizeof(acc),1,fp)==1)
{
if (acc.balance<MINBAL)
{

printf("%d\t%s\t%.2f\n",acc.accno,acc.accname,acc.balance);
count++;
}
}
fclose(fp);
printf("\nNumber of account holders whose balance is less
than minimum:%d",count);
break;
}
case 0:
exit(0);
}
} while(choice>0);
return 0;
}

You might also like