title: How to use fgets after using fgetc?
body: <p>I'm trying to write a specific program that reads data from a file but I realized that when I read the file with fgetc, if I use fgets later, it doesn't have any output.</p>
  <p>For example, this code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main() {
      FILE * arq = fopen(&quot;arquivo.txt&quot;, &quot;r&quot;);
      char enter = fgetc(arq);
      int line_count = 1;
      
      while(enter != EOF) {
          if (enter == '\n') line_count++;
          enter = fgetc(arq);
      }
  
      printf(&quot;%d&quot;, line_count);
      char str[128];
  
      while(fgets(str, 128, arq)) printf(&quot;%s&quot;, str);
  }
  </code></pre>
  <p>the second <code>while</code> doesn't print anything but if I delete the first <code>while</code>, the code prints the file content. Why is that happening?</p>