title: Counting input characters in C
body: <p>I have just started learning C, been reading a C textbook by Keringhan and Ritchie. There was this example in the textbook, counting characters from user input. Here's the code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  main() 
  {
      long nc;
      nc = 0;
  
      while(getchar() != EOF) {
          if (getchar() != 'q')       
              ++nc;
          else 
              break;      
      }
  
      printf("%ld\n", nc);        
  }
  </code></pre>
  
  <p>The problem is, when I execute the code, if I input only one character per line, when I input "q" to break, it doesn't do so. I have to type some word per line, only after that it will break the loop. Also, it only counts the half of the characters of the word. I.e. if I input </p>
  
  <pre><code>a
  b
  russia
  </code></pre>
  
  <p>it will only print '5' as final result. </p>
  
  <p>Could you please explain to me why is this happening?</p>