Why is getchar() not working for me?

Viewed 1601

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?

4 Answers
Related