title: fgetc null terminator
body: <p>I'm doing an exercise in K&amp;R:</p>
  
  <blockquote>
    <p>Write a program detab that replaces tabs in the input with the proper number of blanks to space to the next tab stop.</p>
  </blockquote>
  
  <p>And this is what I have so far (w/o error checking on the file):</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #define tab 2
  #define MAX_LENGTH 1000
  int main(int argc, char **argv)
  {
      FILE *fp = fopen(argv[1], "r+");    
      int c, n;
      char buffer[MAX_LENGTH + 1];
      for (n = 0; n &lt; MAX_LENGTH &amp;&amp; (c = fgetc(fp)) != EOF; ++n) {
          if (c == '\t') {
              for (int x = 0; x &lt; tab; ++x)
                  buffer[n++] = ' ';
              --n;
          }
          else
              buffer[n] = c;
      }
      //buffer[n] = '\0';
      //rewind(fp);
      //fputs(buffer, fp);
      printf("%s\n", buffer);
      fclose(fp);
      return 0;
  }
  </code></pre>
  
  <p>It seems to work, but I'm wondering why <code>\0</code> wasn't needed at the end. Was I just lucky?</p>