title: fwrite keeps failing not sure why
body: <p>In my code below, the file is being written correctly as far as I can tell. When I look in the file floats.dat I see this stream of binary <code>ÍÌL@33c@ÍÌÜ@ffFAßOeA^@^@bBf6zE33äCff&lt;83&gt;BÍÌ¦B</code></p>
  
  <p>However my program always ends up triggering this if statement:</p>
  
  <pre><code>if(fread(inputFloats, sizeof(float), LENGTH, binaryFile) &lt; LENGTH)
  {
     fprintf(stderr, "Problem reading some or all data from %s\n\n", binaryFileName);
     return EXIT_FAILURE;
  }
  </code></pre>
  
  <p>Does anybody see something I've done wrong here? Full code below.</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #define LENGTH 10
  
  int main(void)
  {
     FILE *binaryFile, *textFile;
     char *binaryFileName = "floats.dat", *textFileName = "floats.txt";
     float floats[LENGTH] = {3.2, 3.55, 6.9, 12.4, 14.332, 56.5, 4003.4, 456.4, 65.7, 83.4};
     float inputFloats[LENGTH];
     int i;
  
     if((binaryFile = fopen(binaryFileName, "r+")) == NULL)
     {
        fprintf(stderr, "Problem opening %s", binaryFileName);
     }
  
     if(fwrite(floats, sizeof(float), LENGTH, binaryFile) &lt; LENGTH)
     {
        fprintf(stderr, "Problem writing some or all data to %s\n", binaryFileName);
        return EXIT_FAILURE;
     }
  
     printf("DATA WRITTEN SUCCESSFULLY\n");
  
     if(fread(inputFloats, sizeof(float), LENGTH, binaryFile) &lt; LENGTH)
     {
        fprintf(stderr, "Problem reading some or all data from %s\n\n", binaryFileName);
        return EXIT_FAILURE;
     }
  
     for(i = 0; i &lt; LENGTH; i++)
     {
        printf("float[%d] = %f\n", i, floats[i]);
     }
  
     return EXIT_SUCCESS;
  }
  </code></pre>