title: Count number of whitespaces in a character string in c
body: <pre><code>#include &lt;stdio.h&gt;                  
  
  int main (){
  int d=0;                          
  int e;                           
  while ((e=getchar())!=EOF)  {   
  if(e==' '){ 
  d++;
  }
  if(e=='\n')
  return 0;
  printf("%d",d);
  
  }
  }
  </code></pre>
  
  <p>When i run this code if i type in "hello sir how are you" as my input string, the result i get is 000001111222233334444.. obviously there are 4 whitespace characters, how do i get my code to print out 4 instead of counting the number of whitespaces for every character entered</p>