|
From: Ray K. <kul...@wr...> - 2006-01-11 04:29:57
|
As kalb mentioned, you can send it an end of file character using an
escape sequence to terminate the loop.
Another way would be to change the test to
for (nc = 0; '\n' != getchar(); ++nc);
That will test for a newline instead of EOF, which should make the loop
terminate when you hit the enter key.
"Gary Lefebvre" <gar...@co...> wrote:
> #include <stdio.h>
> #include <stdlib.h>
> main()
> {
> long nc;
> nc=0;
> for (nc=0; getchar()!=EOF; ++nc);
> printf("%ld\n",nc);
> system("Pause");
> return 0;
> }
> No matter what loop option I try I have the same result. The loop does
> not
> terminate when, after entering text, I press the enter key. The command
> window hangs. The loop will not terminate to proceed to the rest of the
> code.
|