nested while loops possible?
sorry for bugging you guys, last question i promise ;)
Ok this code needs to
1)read id and quantity records from a newSupply.txt
2)read id record from inventory.dat
3)if there is a corresponding id in inventory.dat add newSupply.quantity to inventory.quantity.
4)if there has been a typo or something in newsupply.txt and no matching id record is found in inventory.dat write incorrect data to exception.txt
Basically the only way i know to open a file and read it is to loop and read 1 record at a time, so what i tried to do was get the program to
1)get the first id record in newSupply file
2)get first id record in inventory file
3) see if they match, if not loop until a match is found. if a match is found update.
4)if no match is found the updated variable stays at 0 and data written to exception.txt file
5)get next id record in newSupply file and repeat until EOF in Supply.txt
Here is what Ive done so far, which i was quite proud of until I realised it did absolutly nothing :(
Code:
void updateInventory(void)
{
FILE *inFile;
FILE *exceptionFile;
FILE *supplyFile;
parts_struct parts;
int updated;
updated = 0;
newParts_struct newParts;
inFile = openFile(inFileName, "rb+");
supplyFile = openFile(newSupplyFile, "r");
exceptionFile = openFile(exceptionFileName, "w");
while(!feof(supplyFile))
{
newParts = readNewSupply(supplyFile);
while(!feof(inFile))
{
parts = readParts(inFile);
if (newParts.id == parts.id)
{
parts.qtyAvailable = parts.qtyAvailable + newParts.quantity;
updated =1;
}
}
if (updated = 0)
fprintf(exceptionFile, "%s %-20s %4d", newParts.id, newParts.description, newParts.quantity);
}
I really cant see why this wont work, the inner loop just doesnt seem to be looping, not even once i dont think.
Im sure there are much better, more correct ways to do this but bare in mind in new.
Can anyone see where im going wrong?