Hi there. I want to save the inventory in a txt file. Am using structures . When the user chooses to save in the menu i want to write the whole inventory to a txt file.
my structure looks like this
Code:
struct inventory
{
char title[25];
char pub_date[9];
char author[20];
int num;
int on_order;
float retail;
};
The function witch is supposed to save the invenoty looks like this
Code:
int save(inventory book[1000], int total)
{
fp.open("books.txt", ios::in | ios::out );
fp.write((unsigned char *)&book, sizeof(inventory));
fp.close();
return 0;
}
This doesn't show any errors but when i open the txt file it shows
some garbage characters. Also the read() command doesnt work.
Am using the write() comand correctly?
If please someone can show me an example of write(), and read()
with structures it would really help me.
attached the whole code if enyone wants to look at it. (book inventory program witch i just added the save function to test)
Thanx for your help.