title: Read & Write file into array
body: <p>I am trying to write to a text file and read from text file to get the average score of items in an array. Here is my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  int main()
  {
  float total =0;;
  
  ofstream out_file;
  out_file.open("number.txt");
  
  const int size = 5;
  double num_array[] = {1,2,3,4,5}; 
  
  for (int count = 0; count &lt; size; count++)
  {
      if (num_array[count] == 0)
      {
          cout &lt;&lt; "0 digit detected. " &lt;&lt; endl;
          system("PAUSE");
      }
  }
  double* a = num_array;
  out_file &lt;&lt; &amp;a;
  
  out_file.close();
  
  ifstream in_file;
  in_file.open("number.txt");
  if(in_file.fail())
  {
      cout &lt;&lt; "File opening error" &lt;&lt; endl;
  }else{
      for (int count =0; count&lt; size; count++){
          total += *a;  // Access the element a currently points to
          *a++;  // Move the pointer by one position forward
      }
  }
  
  cout &lt;&lt; total/size &lt;&lt; endl;
  
  system("PAUSE");
  return 0;
  }
  </code></pre>
  
  <p>However, this program just simply execute without reading from a file and return the correct average score. And this is what I get in my text file : </p>
  
  <blockquote>
    <p>0035FDE8</p>
  </blockquote>
  
  <p>I thought it supposed to write the entire array into text file, and from there I retrieve the elements and calculate for the average?</p>
  
  <p><strong>Edited Portion</strong></p>
  
  <p>I have fixed the writing to text file part using a for loop on pointer : </p>
  
  <pre><code>for(int count = 0; count &lt; size; count ++){
      out_file &lt;&lt; *a++ &lt;&lt; " " ;
  }
  </code></pre>
  
  <p>But now I having another problem which is I cannot read the file and compute for the average. Anybody know how to fix?</p>