Ok im still having problems.
the code didnt work because my function newParts = readNewSupply(supplyFile) was trying to read a text file like a binary file.
so Ive changed it to just use Fgets to read the strings but when I try and read the first record wich is 6 digits long it reads the entire record instead. so instead of just displaying the ID which is something like abc123 it displays the ID, description and quantity records.
Code:
typedef struct
{
char id[7];
char description[26];
int quantity;
}newParts_struct;
Code:
void updateInventory(void)
{
FILE *inFile;
FILE *exceptionFile;
FILE *supplyFile;
parts_struct parts;
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 (strcmp(newParts.id, parts.id) == 0)
{
printf("Updated");
}
}
}
closeFile(inFile);
closeFile(exceptionFile);
closeFile(supplyFile);
}
Code:
newParts_struct readNewSupply(FILE *supplyFile)
{
newParts_struct newParts;
fgets(newParts.id,7,supplyFile);
printf("%s", id);
return newParts;
}
All im trying to do first is get the first 6 digits which is the id then ill go on from there but it displays the whole file.
what annoys me is that I can get fgets to read exactly how i want it to if I start a new file, but the exact same code wont work in this program.
Any ideas?