title: How to write a floating point array to a file in C?
body: <p>I have an <code>float</code> array, that has 189 elements (running from index 0 to index 188). I'm having trouble writing this array out to a file. Suppose the first element is 45.6, and the second element is 67.9, I want my output file to look like this:</p>
  <pre><code>0, 45.6
  1, 67.9
  </code></pre>
  <p>and so on. I've tried the function shown below, and the result is my output file has odd characters in it.</p>
  <pre class="lang-cpp prettyprint-override"><code>void writeCorrelationToFile(float slidingCorrelator[])
  {  
      FILE *fp;
      fp=fopen(&quot;CorrelationResult.txt&quot;,&quot;w&quot;);
      printf(&quot;inside writeCorrelationToFile, writing out array using fwrite  \n&quot;);
      fwrite(slidingCorrelator,4,sizeof(slidingCorrelator),fp);
      fclose(fp);
  }
  </code></pre>
  <p>I get an output file like this:</p>
  <pre><code>�'���۽l^��(���!&gt;
  </code></pre>
  <p>I have also tried setting <code>sizeof(slidingCorrelator)</code> to 189, but that also did not help.</p>