-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy path11.c
More file actions
30 lines (28 loc) · 701 Bytes
/
Copy path11.c
File metadata and controls
30 lines (28 loc) · 701 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
29
30
#include <stdio.h>
struct Product
{
int code;
char name[20];
float cost;
int quantity;
};
int main()
{
FILE *fp;
fp = fopen("products.txt", "w");
struct Product products[5];
for (int i = 0; i < 5; i++)
{
printf("\nEnter product code: ");
scanf("%d", &products[i].code);
printf("Enter product name: ");
scanf("%s", products[i].name);
printf("Enter product cost: ");
scanf("%f", &products[i].cost);
printf("Enter product quantity: ");
scanf("%d", &products[i].quantity);
fprintf(fp, "%d %f %d\n", products[i].code, products[i].cost, products[i].quantity);
}
fclose(fp);
return 0;
}