title: How to use EOF to read all data from file
body: <p>I'm learning about file i/o in C language and I wrote this program that reads a file, and then for every even number found, it has to print <code>*</code> to the screen.</p>
  
  <p>My problem is that my program keeps printing <code>*</code> forever. </p>
  
  <p>I have tried different ways,some from this website, but I can't seem to understand how to read until end of a text file using EOF.</p>
  
  <p>I want to learn how to read a text file until the end of the file please.
  How do I read until the end of a text file? EOF in C.</p>
  
  <pre><code>
  int main(void)
   {
  
       int num;
       FILE *ifp;
  
       ifp = fopen("numbers.txt", "r" );
  
       if(ifp == NULL)
       {
           exit(1);
       }
  
       do
       {
           fscanf(ifp, "%d", &amp;num);       
  
              if(num%2 == 0)
  
                  {
                  printf("*\n");
                  }
          } while(num != EOF);
  
  
      fclose(ifp);
  
      return 0;
  }
  
  </code></pre>