title: Do i really need commented fclose() commands?
body: <p>The following program was taken from <em>Windows System Programming</em> (Fourth Edition) by Johnson M. Hart:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;errno.h&gt;
  
  #define BUF_SIZE 256
  
  int main(int argc, char *argv[])
  {
      FILE *inFile, *outFile;
      size_t bytesIn, bytesOut;
      char rec[BUF_SIZE];
  
      if (argc != 3) {
          printf("Syntax : scp source destination.\n");
          return 1;
      }
  
      inFile = fopen(argv[1], "rb");
      if (inFile == NULL) {
          perror(argv[1]);
          return 2;
      }
  
      outFile = fopen(argv[2], "wb");
      if (outFile == NULL) {
          perror(argv[2]);
          //fclose(inFile);
          return 3;
      }
  
      while ((bytesIn = fread(rec, 1, BUF_SIZE, inFile)) &gt; 0) {
          bytesOut = fwrite(rec, 1, bytesIn, outFile);
          if (bytesIn != bytesOut) {
              perror("Fatal write error.");
              //fclose(inFile); fclose(outFile);
              return 4;
          }
      }
  
      fclose(inFile);
      fclose(outFile);
      return 0;
  }
  </code></pre>
  
  <p>It works the same with or without closing the files in the commented lines.<br>
  However, after having read previous posts I am not sure what is the best practice.<br>
  Let OS do its job or close them whenever I feel I should?<br>
  I am saying this because I have seen situations in windows GUI apps that, when I close the handles instead of the OS, I am causing a small glitch on the screen and I am essentially delaying the OS because I do the cleaning like many C++ books say.<br>
  I am not using anything windows here...it's a CRT implementation but still... </p>