I am trying to write an inventory system program and I can only get it display the date or the item name ( should be coke). Depending on if i have the date string or not with fscanf. If I remove that fscanf for the date it shows the item name. if I have the date scanned in it wont show the Item name. Any help?
{
FILE *ifp;
ifp = fopen(filename, "r");
int x = 0;
fscanf(ifp, "%d",&x);
//printf("%d",x);
for (int i = 0; i < x ; ++i)
{
fgets(inventory_list[i].name,strlen(inventory_list[i].name), ifp);
fscanf(ifp, "%d", &inventory_list[i].quant);
fscanf(ifp, "%lf", &inventory_list[i].price);
fscanf(ifp, "%d", &inventory_list[i].id);
fscanf(ifp, "%s", inventory_list[i].date);
}
and here is the print function I have tried it all as one and i have tried it all separate.
printf("%s",inventory_list[1].name);
printf(" %d \n %.2lf \n %d \n %s ", inventory_list[1].quant,inventory_list[1].price,inventory_list[1].id,inventory_list[1].date);
Here is the structure :
struct inventory_item
{
char name[50];
int quant;
double price;
int id;
char date[10];
};
typedef struct inventory_item inventory;
format of the input file is:
3 total number or items to be sorted
coke name
79 amount of items
2.21 cost of items
12657435 item ID
12/21/2019 DATE