title: Program Reading Last Line of File Twice
body: <p>I am writing a program that reads a <code>.txt</code> file line by line. I have been able to do this so far, but the last line of the file is read twice. I can't seem to figure out why. Thank you for your help in advance! Here is the code I have: </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  #define MAX_LINELENGTH 200
  
  int main(int argc, char* argv[])
  {
      FILE* textFile;
      char buffer[MAX_LINELENGTH];
      char strName[40];
      int numCharsTot;
      int numWordsInMesg;
      int numCharsInMesg;
  
      textFile = fopen(argv[1], "r");
      if(textFile == NULL)
      {
          printf("Error while opening the file.\n");
          return 0;
      }
      while(!feof(textFile))
      {
          fgets(buffer, MAX_LINELENGTH, textFile); //Gets a line from file
          //printf("Got Line: %s\n", buffer);
      }
  }
  </code></pre>