-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathFile Handling3.c
More file actions
28 lines (28 loc) · 768 Bytes
/
File Handling3.c
File metadata and controls
28 lines (28 loc) · 768 Bytes
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
#include<stdio.h>
int main(){
FILE *fp;
int number,quantity,i;
float price,value;
char item[10],filename[10];
printf("Input file name\n");
scanf("%s",filename);
fp=fopen(filename,"w");
printf("Input inventory data\n\n");
printf("Item name Number Price Quantity\n");
for(i=1;i<=3;i++)
{
fscanf(stdin,"%s %d %f %d",&item,&number,&price,&quantity);
fprintf(fp,"%s %d %f %d",item,number,price,quantity);
}
fclose(fp);
fprintf(stdout,"\n\n");
fp=fopen(filename,"r");
printf("Item name Number Price Quantity Value\n");
for(i=1;i<=3;i++)
{
fscanf(fp,"%s %d %f %d",&item,&number,&price,&quantity);
value=price*quantity;
fprintf(stdout,"%-8s %7d %8.2f %8d %11.2f\n",item,number,price,quantity,value);
}
fclose(fp);
}