Im having trouble on getting the quantity up of the variable "item.iqty". For example the current quantity is 5 and in this function, the user inputs a number and it should add to the variable "item.iqty". So if if the user inputs 2 then the current quantity should be 7 now but in my program it hasnt changed. its still 5
system("cls");
printf("Add item quantity");
FLUSH;
printf("\n\nEnter Item number: ");
scanf("%d",&num);
fp = fopen("d:/Files/INVENTORY.txt","rb");
fp1 = fopen("d:/Files/RECEIPTS.txt","wb");
if ((fp = fopen("d:/Files/INVENTORY.dat","r+b")) == NULL)
{
printf("Record not found");
getch();
}
else
{
found = itemNum(fp, &item, num);
if (found)
{
fclose(fp);
fclose(fp1);
fp = fopen("d:/Files/INVENTORY.txt","rb");
fscanf(fp, "%d", &item.iqty);
fp1 = fopen("d:/Files/RECEIPTS.txt","wb");
fscanf(fp1, "%d", &item.iqty);
printf("How many %s/s will be added?", item.iname);
printf("\nEnter here: ");
scanf("%d", &qty);
FLUSH;
item.iqty += qty;
printf("Item quantity is now %d", item.iqty);
c = ftell(fp);
n = c - sizeof(ITEM);
fseek(fp, n, SEEK_SET);
fwrite(&item,sizeof(ITEM),1,fp);
fwrite(&item,sizeof(ITEM),1,fp1);
}
}
fclose(fp);
fclose(fp1);
return;
}