title: C - Can't get the number of lines in text file? Are there other ways to get?
body: <p>I want program count lines in text file by function. It used to work ,but it always return 0 now.
  What am I doing wrong?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int couLineF(FILE* fp){ //count lines in file
      int count = 0,ch;
      while((ch = fgetc(fp)) != EOF){
          if(ch == (int)"\n" ) count++;
      }
      rewind(fp);
      return count;
  }
  
  int main(){
  
       FILE *fp = fopen("book.txt","r");
      int lines;
          if(fp){
              lines = couLineF(fp);
              printf("number of lines is : %d",lines);
  
          }
  
          return 0;
  
  }
  </code></pre>
  
  <hr>
  
  <h2>Another question</h2>
  
  <p>Are there any other ways to get number of lines in text file?</p>