title: How to traverse C loop correctly using File Pointer only
body: <p>I am making a program in c that reads line by line and does some operation on the elements of every line. I am calling my read_row function like this.</p>
  
  <pre><code>while(filePointer!=NULL)
  {
          int result=readRow(filePointer,headerRow,lineRow);
          printf("The value of  row is |%d|\n",result);
  }
  </code></pre>
  
  <p>Inside my read_row function I am using get c to traverse through the line.</p>
  
  <pre><code> cc=getc(fp);
      while((cc!='\n') &amp;&amp; (cc!= EOF))
      {
  
              *line=cc;
              line++;  
              if(cc==',')
              {
                  counterr++;
              }
              cc=getc(fp);
  
      }  
  
      if(cc==EOF)
      {
          fp=NULL;
      }
  </code></pre>
  
  <p>I am trying traverse through all the lines. However, this loop is infinite as file pointer never goes to null. I have tried to set the file pointer to null if the cc equals to EOF. However, this did not help at all. Therefore, please explain how should I properly terminate that loop. I believe that '\n' is coming before the EOF.Therefore, the file pointer is not getting to null. I have to do it using the file Pointer, as I have already made a very big program based on that logic. Moreover, I could only find examples that used methods like fgets() to traverse. </p>