I dont know much about structures so i need help.
I am making a database.....for say WAL-MART.
WHat I am trying to do is to read from a file (WMinventory.dat) and send data from the file to a structure, but I get a bunch of error which i still havent been able to fix.
To make it easier for me i took the programme down to its simplest form.....i cant even read one line from the file.
Heres my STructure:
Code:
typedef struct{
char name [50];
float price;
int noofItems;
char expiry;
char type;
char detail;
}structure;
Heres the first 6 lines from my data file.
Code:
Sony 29" TV
699.99
5
N/A
Electronic
Flat Screen WEGA
Heres my attempt....i am trying to read one line (Sony 29" TV) and put it in (char name [50].
Code:
#define dataFileName "WMinventory.dat"
#define MAXchar (100)
void loadData(structure ,FILE *);
FILE *open_file(char [], char []);
int main(void)
{
structure inventory;
FILE *dataFile;
dataFile = open_file(dataFileName ,"r");
loadData(inventory,dataFile);
puts(inventory.name);
fclose(dataFile);
getchar();
return 0;
}
void loadData(structure inventory,FILE *dataFile)
{
fgets(inventory.name, MAXchar,dataFile);
}
FILE *open_file(char fileName[], char accessType[])
{
FILE *fptr;
if ( NULL == (fptr = fopen(fileName, accessType))) {
puts("FILE OPEN ERROR:");
puts(fileName);
puts("\n");
system ("pause");
abort();
}
return fptr;
}
When i try to compile i get this error:
" undefined reference to `loadData(structure*, _iobuf*)' "
If i figure this out the rest of the program will become easier....any help would be appreciated.
[EDIT:] Changed a few things around and now I get this error:
"cannot convert `structure' to `structure*' for argument `1' to `void loadData(structure*, FILE*)"
[EDIT:] Changed some more things and now i'm stuck....the program runs but prints out some garbage...._"3½┬wHô├8="