title: Read characters from a file and store them in a variable in C
body: <p>I am trying to read character by character from a file and store the characters in a variable.</p>
  
  <p>Only the content from the first line of the file is required so I am using <code>\n</code> or <code>EOF</code> to stop reading. It is required to store <code>SPACE</code> also.</p>
  
  <p>Here is my program:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  
  void main()
  {
    FILE *fp;
    char ch;
    char txt[30];
    int len;
    fp=fopen("~/hello.txt","r");
    ch=fgetc(fp);
    while(ch != EOF || ch!="\n")
    {
      txt[len]=ch;
      len++;
      ch=fgetc(fp);
    }
     puts(txt);
  }
  </code></pre>
  
  <p>But I am getting a warning while compiling like comparison between pointer and integer. And when I run it I am getting a segmentation fault.</p>