#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define SIZE 30
struct purchase
{
char pur_desc[SIZE];
int pur_unit;
int pur_quantity;
int pur_total;
};
void main()
{
FILE *fp,*fout;
char *filename;
int grnd_total=0;
struct purchase p1;
int flag=0;
p1.pur_quantity=99;
p1.pur_total=0;
clrscr();
fp=fopen("input11.txt","w");
if(fp==NULL)
{
printf("\n THE FILE CANNOT BE OPENED");
exit(getch());
}
printf("\n ENTER 0 FOR THE QUANTITY TO TERMINATE......");
while(p1.pur_quantity!=0)
{
flushall();
printf("\n ENTER THE DESCRIPTION OF THE ITEM ::");
scanf("%[^\n]",p1.pur_desc);
flushall();
printf("\n ENTER THE UNIT PRICE OF THE ITEM::");
scanf("%d",&p1.pur_unit);
flushall();
printf("\n ENTER THE QUANTITY OF THE ITEM::");
scanf("%u",&p1.pur_quantity);
p1.pur_total=p1.pur_unit*p1.pur_quantity;
fprintf(fp,"%s %d %u %d\n",p1.pur_desc,p1.pur_unit,p1.pur_quantity,p1.pur_total);
}
clrscr();
fclose(fp);
fp=fopen("input11.txt","r");
fout=fopen("output11.txt","w");
fprintf(fout,"\n THE INFORMATION OF THE BUYER IS AS FOLLOWS::");
fprintf(fout,"\n DESCRIPION\tUNIT PRICE\tQUANTITY\tTOTAL");
while(fscanf(fp,"%s %d %u %d",p1.pur_desc,&p1.pur_unit,&p1.pur_quantity,&p1.pur_total)!=EOF)
{
if(p1.pur_quantity!=0)
{
flag=1;
fprintf(fout,"\n %s\t\t %d\t %u\t %d",p1.pur_desc,p1.pur_unit,p1.pur_quantity,p1.pur_total);
grnd_total=grnd_total+p1.pur_total;
}
}
fclose(fp);
if(flag==0)
{
fprintf(fout,"\n THERE IS NO RECORD IN THE FILE");
exit(getch());
}
else
{
fprintf(fout,"\n THE GRAND TOTAL===\t\t\t %d",grnd_total);
getch();
}
}
*********************INPUT****************************************
rice 10 10 100
tea 70 2 140
df 0 0 0
*********************OUTPUT****************************************
THE INFORMATION OF THE BUYER IS AS FOLLOWS::
DESCRIPION UNIT PRICE QUANTITY TOTAL
rice 10 10 100
tea 70 2 140
THE GRAND TOTAL=== 240