title: How to read files from a file in C++ using fread and buffering?
body: <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  FILE *in, *out;
  
  using namespace std;
  
  int main(int argc, char** argv)
  {
      in = fopen("share.in", "r");
      int days;
      int size;
      int offset = 0;
      fscanf(in, "%d", &amp;days);
  
      fseek(in, 0L, SEEK_END);
  
  #if defined(_WIN32)
      size = ftell(in) - 1;
  #elif defined (_WIN64)
      size = ftell(in) - 1;
  #else
      size = ftell(in);
  #endif // defined
  
      fseek(in, 0L, SEEK_SET);
  
      char *buffer = (char*) malloc(size + 1);
      char *token;
  
      fread(buffer, 1, size, in);
      buffer[size] = '\n';
  
      int *values = (int*) malloc(days * sizeof(int));
      int i;
  
      while (*buffer != '\n'){
          buffer++;
      }
  
      buffer++;
      cout &lt;&lt; days &lt;&lt; endl;
      cout &lt;&lt; endl;
  
      for (i = 0; i &lt; days; i++){
          values[i] = 0;
  
          while (*buffer != '\n'){
              values[i] = (values[i] * 10) + (*buffer - '0');
              buffer++;
          }
  
          buffer++;
      }
      for (int i = 0; i &lt; days; i++){
          cout &lt;&lt; values[i] &lt;&lt; endl;
      }
  
  }
  </code></pre>
  
  <p>The file I want to read is this:</p>
  
  <pre><code>20 
  10 
  7
  19
  20
  19
  7
  1
  1
  514
  8
  5665
  10
  20
  17
  16
  20
  17
  20
  2
  16
  </code></pre>
  
  <p>I want the first to be stored in the variable days which is tha size of the array, and the rest in the array, but it reads everything but the last number. <strong><em>Each number is in an new line.</em></strong> What can I change about it? I am thinking sth in the last while condition. Thank you</p>