Thanks Salem,
by passing parameters you mean passing the variables through the functions rather then declaring them in callfunction? if you understand that...
Code:
#include <stdio.h>
#include <ctype.h>
#define inFileName "parts.dat"
#define outFileName "test.txt"
typedef struct
{
char description[21];
double costPrice;
} item_struct;
typedef struct
{
char itemNumber[7];
item_struct item;
int qtyAvailable;
int reorderLevel;
} parts_struct;
parts_struct readPart(FILE *);
void writePart(parts_struct, FILE *);
void displayRecord(parts_struct );
void callfunction (parts_struct, FILE *);
int main()
{
parts_struct part;
FILE *inFile, *outFile;
inFile = openFile(inFileName, "rb");
outFile = openFile(outFileName, "w");
part = readPart(inFile);
while(!feof(inFile))
{
displayRecord(part);
callfunction(part, outFile);
part = readPart(inFile);
}
closeFile(inFile);
closeFile(outFile);
return 0;
}
void displayRecord(parts_struct part)
{
printf("%s %-20s %6.2lf %4d %4d\n", part.itemNumber, part.item.description,
part.item.costPrice, part.qtyAvailable, part.reorderLevel);
}
void writePart(parts_struct part, FILE *outFile)
{
fprintf(outFile, "%s %-20s %6.2lf %4d %4d\n", part.itemNumber, part.item.description,
part.item.costPrice, part.qtyAvailable, part.reorderLevel);
}
parts_struct readPart(FILE *inFile)
{
parts_struct part;
fread(&part, sizeof(part), 1, inFile);
return part;
}
void callfunction(parts_struct part, outFile)
{
writePart(part, outFile);
}
I think im getting confused with the function prototypes and headers because im getting a few errors when I try this.
any ideas?
Thanks alot.