title: counting the number of sentences in a paragraph in c
body: <p>As part of my course, I have to learn C using Turbo C (unfortunately).</p>
  
  <p>Our teacher asked us to make a piece of code that counts the number of characters, words and sentences in a paragraph (only using printf, getch() and a while loop.. he doesn't want us to use any other commands yet). Here is the code I wrote:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;conio.h&gt;
  
  void main(void)  
  {  
  clrscr();  
  int count = 0;  
  int words = 0;  
  int sentences = 0;  
  char ch;
  
  while ((ch = getch()) != '\n')
  {
      printf("%c", ch);
      while ((ch = getch()) != '.')
      {
          printf("%c", ch);
          while ((ch = getch()) != ' ')
          {
              printf("%c", ch);
              count++;
          }
          printf("%c", ch);
          words++;
      }
      sentences++;
  }
  
  printf("The number of characters are %d", count);
  printf("\nThe number of words are %d", words);
  printf("\nThe number of sentences are %d", sentences);
  getch();
     }
  </code></pre>
  
  <p>It does work (counts the number of characters and words at least). However when I compile the code and check it out on the console window I can't get the program to stop running. It is supposed to end as soon as I input the enter key. Why is that?</p>