title: Segmentation fault while reading file
body: <p>My file looks like: </p>
  
  <pre><code>123456789
  </code></pre>
  
  <p>My code gives me segmentation fault: </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(){
  
      FILE *f; 
      char ch[5];
      f = open("a.txt", "r");
      fgets( ch, 4, f); 
      ch[4] = NULL;
      printf("%s", ch); //Fixed
      return 0;
  }
  </code></pre>
  
  <p>I am an absolute beginner. What am I doing wrong. My aim is to read first 4 characters of the file using <code>fgets</code>.</p>