title: Reading, a set line range from a file in C
body: <p>I' am writing a C program which allows the user to dynamically specify the File name from which the data is to be read. Next the user enters a lower bound and an upper bound. The data in the lines from between the bounds is to be printed.</p>
  <p>For this the main function makes a call: <code>readValues(cTargetName, iLower, iHiger);</code></p>
  <p>The function <code>readValues</code> is supposed to work as follows:</p>
  <ol>
  <li>Check if file exist, if yes. Open it with <code>fopen</code></li>
  <li>Read with <code>feof</code> and <code>fgets</code> line by line the whole file, and store each line in <code>char string</code></li>
  <li>With a for loop, print the correct range of lines from the string</li>
  </ol>
  <p><strong>I'm not sure why but the while loop doesn't seem to exit although I use the <code>feof</code> statement, which should terminate after the end of the File is reached.</strong></p>
  <p>The code looks as follows:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void readValues(char cFileName[75], int n, int m)
  {
      //Variable declaration;
      char strArray[50][50];
      char *parser;
      int i = 0;
  
      FILE *Data;
  
      if(Data = fopen(cFileName, &quot;rt&quot;) == NULL){
          printf(&quot;File could not be opened&quot;);
          return 1; //Can you return 1 in a void function?
      }
  
      //Read the file line by line
      while(feof(Data)==0){
          fgets(strArray[i], 200, Data);
          i++;
      }
  
      //Reading the specified lines
      for(n; n&lt;=m; n++){
          printf(&quot;%s&quot;, strArray[n]);
      }
  }
  
  
  int main()
  {
      char cTargetName[75] = {&quot;C:/Users/User1/Desktop/C_Projects_1/TestData.txt&quot;};
      int iLower = 2;
      int iHiger = 4;
  
      readValues(cTargetName, iLower, iHiger);
  
      return 0;
  }
  </code></pre>
  <p>All help is appreciated. Thanks in advance!</p>