title: counting the number of characters per line from a text file in C
body: <p>so I am trying to count the number of characters in each line of the text file. I have successfully counted them but can't seem to get the last line of the text counted. here is my code</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  #define MAXLINE 1000
  #define NEWLINE '\n'
  
  int 
  main(int argc, char*argv[]){
      int bytes =-1, lines = 1;
      char x,line[MAXLINE];
      FILE *file;
  
      file = fopen("no.txt","r");
      printf("s0: query = \"%s\"\n",argv[1]);
      printf("---\n");
  
      if (file == NULL){
          printf("File doesn't exist \n");
          exit(EXIT_FAILURE);
      }
  
      while( fgets (line, 1000, file)!=NULL ) 
      {
          printf("%s",line); 
  
          while((x = getchar())!= EOF ){
              bytes +=1;
              if (x == NEWLINE){
                  printf("S1: line %6d, bytes = %3d\n---\n",lines,bytes);
                  bytes = -1;
                  break;
              }
          }
          lines +=1;
      } 
  
      fclose(file);
      return 0;
  }
  </code></pre>