Explain Program count chacracter, please

when i start running the program, i can't exit while loop when input character, so the program isn't print the value of nc.

1
2
3
4
5
6
7
8
9
  #include <stdio.h>
  main()
  {
     long nc;
     nc=0;
     while(getchar()!=EOF)
     ++nc;
     printf("%ld\n",nc);
  }
EOF is checking for the end of a file, your not working with files.

http://www.cplusplus.com/reference/cstdio/EOF/
While that is what the acronym stands for, EOF is used for the end of streams in general, not just the end of file streams.

If you're in a Windows console, you can terminate input by pressing Ctrl+Z - this will end the input stream completely.
Last edited on
Ok, Thank all
Topic archived. No new replies allowed.