title: Is having two scanf or getchar() inside and outside a loop necessary?
body: <p>I saw this little program that calculates the characters length in my practice book, and I am a bit confused. Why is there two <code>getchar()</code>, one outside of and one inside the loop? </p>
  
  <p>I removed the <code>getchar()</code> outside of the loop and don't see any difference. Is there any consequence if I delete it? </p>
  
  <p>Here is the code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  char ch;
  int len;
  
  printf("Enter your message:");
  ch = getchar();
  
  while(ch != '\n') {
      len++;
      ch = getchar();
  }
  
  printf("Your message is %d characters long", len);
  return 0;
  
  </code></pre>
  
  <p>And here is my modified version, I have no idea if there's any drastic consequence since the output is the same:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  char ch;
  int len;
  
  printf("Enter your message:");
  
  while(ch != '\n') {
      ch = getchar();
      len++;
  }
  
  printf("Your message is %d characters long", len);
  return 0;
  
  </code></pre>