title: Writing to a file in C with two fprintf statements
body: <p>I'm trying to write two different things to a file: an array of over 1,000 elements, and the average and median of the elements. I can print the array fine, but when I try to add the median or mean to it, the program quits partway through printing the array to the console and doesn't print to the file. This is my code: </p>
  
  <pre><code>char fName[20] = "file";
                 /*creating a file*/
                 fp=fopen(fName,"w");
                 int q = 0;
                 while ( q&lt;num ) {
                     fprintf(fp, "%.3f\n", mergedArray[q]);
                     q++;
  
                 }
  </code></pre>
  
  <p>//the above part works fine. the part below is what i can't seem to figure
       out. I've tried putting it underneath the q++; of the while statement but that also crashed it. </p>
  
  <pre><code>fprintf("The median: %lf \nThe average: %lf", &amp;median, &amp;avg);
  
  // Close the file
  fclose(fp);
  </code></pre>