title: fopen and sync with disk
body: <p>I wrote a program that it must write struct to binary file and read from it.
  I use fread, fwrite , fopen , fseek and fclose.
  I wrote the following function that prints all of record in my file.</p>
  
  <pre><code>void ReadFile::printList(){
  //  clearerr(bookFilePtr);
  
      fseek(bookFilePtr,0L,SEEK_SET); // set to begin of file
  
      int counter = 1;
      long int line = 1;
      int pageCounter = 1;
  
      while (this-&gt;readFromFile() == 1){
          string output;
          mvprintw(++line, 27,"***Title*****************Value*********" );
          output = "Name:               " + bookPtrObj-&gt;name;
          mvprintw(++line, 27, output.data());
          output = "Publisher:          " + bookPtrObj-&gt;publisher;
          mvprintw(++line, 27,output.data());
          output = "Author:             " + bookPtrObj-&gt;author;
          mvprintw(++line, 27,output.data());
          output = "Translator:         " + bookPtrObj-&gt;translator;
          if (bookPtrObj-&gt;translation == true )
              mvprintw(++line, 27,output.data());
          if (bookPtrObj-&gt;stock != true )
              mvprintw(++line, 27,"Stock:              The given book doesn't exist.");
          else
              mvprintw(++line, 27,"Stock:              The given book exist.");
          if ( pageCounter % 3 == 0){
              mvprintw(++line, 27,"Press any key to see next page...");
              getch();
              clear();
              line = 1;
  
          }
          pageCounter++;
          refresh();
          fseek(bookFilePtr, counter * sizeof(struct book) ,SEEK_SET); // seek to next data
          counter ++;
      }
  //  fflush(bookFilePtr);
  
      menu();
  }
  </code></pre>
  
  <p><strong>Note:</strong> I run for first and data entry, i can see my data from above func very nice and page to page.But when i exit program , everything are broken.When i run for second time, and run above function, i get <strong>Segmentation fault</strong>, I trace it , bookPtrObj that it is pointer of my struct, can't read my file.I try with type of fopen, [rb. wb, ab+, rb+ , a+, w+ ,aw+]  and so on. but i didn't get result.
  I write to file with the following lines, Of course  i fill element of struct and then run the 2 following lines :</p>
  
  <pre><code>fseek(bookFilePtr,0L,SEEK_END);
  fwrite(ptr,sizeof(struct book),1,bookFilePtr);
  </code></pre>
  
  <p>How do i to stay my data in file?</p>