Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- struct inventory_item
- {
- char productName[50];
- int quantity;
- float price;
- char id[9];
- char date[15];
- };
- int readFile(char filename[], struct inventory_item inventory_list[], int count);
- int getTotalItems(struct inventory_item inventory_list[], int count);
- double getTotalVal(struct inventory_item inventory_list[], int count);
- void printItem(struct inventory_item item)
- {
- // This is an optional function
- }
- int main(int argc, char *argv[])
- {
- if (argc == 2)
- {
- struct inventory_item inventory_list[100];
- int count = readFile(argv[1], inventory_list);
- int totalNumItem = getTotalItems(inventory_list, count);
- float totalVal = getTotalVal(inventory_list, count);
- printf("Total inventory value: $%.2f\n", totalVal);
- printf("Total inventory quantity: %d\n", totalNumItem);
- }
- else
- {
- printf("Error: Unable to open file %s/n", argv[1]);
- }
- return 0;
- }
- int readFile(char filename[], struct inventory_item inventory_list[], int count)
- {
- int i = 0;
- int numberItems = 0;
- FILE * ifp = fopen(filename, "r");
- fscanf(ifp, "%d", &numberItems);
- printf("d\n", numberItems);
- for(i = 0; i < numberItems; i++)
- {
- fscanf(ifp, "%s", &inventory_list[i].productName);
- printf("%s\n", inventory_list[i].productName);
- fscanf(ifp, "%d", &inventory_list[i].quantity);
- printf("%d\n", inventory_list[i].quantity);
- fscanf(ifp, "%.2f", &inventory_list[i].price);
- printf("%.2f\n", inventory_list[i].price);
- fscanf(ifp, "%s", &inventory_list[i].date);
- printf("%s\n", inventory_list[i].date);
- }
- fclose(ifp);
- return numberItems;
- }
- int getTotalItems(struct inventory_item inventory_list[], int count)
- {
- int totprod = 0;
- for(int i = 0; i < count; i++)
- {
- printf("%d\n", inventory_list[i].quantity);
- totprod += inventory_list[i].quantity;
- }
- printf("%d", totprod);
- }
- double getTotalVal(struct inventory_item inventory_list[], int count)
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement