Q:

Why is getchar() not working for me?

I've just started programming c and I'm working through The C Programming Language by Brian W.Kernighan and Dennis M.Richie.
One of the first examples is character counting and the following program is given, but when I enter a string no result it printed.
#include <stdio.h>

main()
{
   long nc;

   nc = 0;
   while (getchar() != EOF)
          ++nc; 
   printf("%ld\n",nc);
 }

Why isn't this working?

A:

You have to finish the input. Your program will count characters until EOF is encountered. EOF, in the keyboard, can be sent by pressing Ctrl-Z then ENTER if you are in Windows, or Ctrl-D then ENTER if you are in Linux/OS X.

A:

as an addition to the answers that were mentioned , here's how to make your program show results when pressing  Enter 
 #include <stdio.h>

main()
{
   long nc;

   nc = 0;
   while (getchar() != '\n')
          ++nc; 
   printf("%ld\n",nc);
 }

