title: problem with fscanf inside while loop in c-language
body: <pre><code>#include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  #include&lt;stdlib.h&gt;
  int main()
  {
          FILE *fp;
          fp=fopen("mydata.txt","r");
          if(fp==NULL)
          {
                  perror("Error while opening");
                  exit(0);
          }
          char *s=(char*)malloc(100);
          while(feof(fp)!=EOF)
          {
                  fscanf(fp,"%[^\n]",s);
                  printf("%s",s);
          }
          return 0;
  }
  </code></pre>
  
  <p>I am trying to read a file line by line.I am getting infinite loop.Where it has gone wrong ? </p>