title: Why does C print an extra line when reading from a file?
body: <p>I'm brand new to C and trying to learn how to read a file.  My file is a simple file (just for testing) which contains the following:</p>
  
  <pre><code>this file
  has been
  successfully read
  by C!
  </code></pre>
  
  <p>So I read the file using the following C code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main() {
  
     char str[100];
     FILE *file = fopen("/myFile/path/test.txt", "r");
  
     if(file == NULL) {
        puts("This file does not exist!");
        return -1;
     }
  
     while(fgets(str, 100, file) != '\0') {
        puts(str);
     }
  
     fclose(file);
  
     return 0;
  }
  </code></pre>
  
  <p>This prints my text like this:</p>
  
  <pre><code>this file
  
  has been
  
  successfully read
  
  by C!
  </code></pre>
  
  <p>When I compile and run it, I pipe its output to <code>hexdump -C</code> and can see an extra <code>0a</code> at the end of each line.</p>
  
  <p>Finally, why do I need to declare an array of chars to read from a file?  What if I don't know how much data is on each line?</p>