Bryan_5 0 Newbie Poster

I'm trying to store some information in a binary file. However, i met with a problem that i can't rectify.

For example, if the first order comes in, there is a struct of information that includes orderNo 1, which will be stored into the binary file.

When there's a second order comes in, the information will be stored along with orderNo 2 into the binary file.

Firstly, i'll create a binary file.

 afile.open(fileName, ios::out | ios::app | ios::binary);

Next, I have a while loop that inputs whatever information

 placeOrder(fstream& afile, const char fileName[])
 {
    while(condition = true)
    {
        .... //whatever cin information
        afile.write(reinterpret_cast <const char*>(&ci), sizeof (ci));
    }
 }

So this placeOrder function will be called again whenever a second order comes in.

Unfortunately, i got this issue where the second order will be combined together with the first order despite appending my files. As a result, order No 1, has both of the records instead of splitting them up to order No 1 and order No 2.

Below is my structure Information

  struct adminInfo
  { 
      char foodName[MAX];
      int amt;
      double price;
      char foodInfo[MAX];
  };

 struct custInfo
 {
     char custName[MAX];
     int tableNo;
     int orderNo;
     adminInfo ai;
     double total;
  };
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.