c programming EOF help

mzonerz

Well-known member
  • Oct 7, 2011
    1,467
    293
    83
    main(){ long nc; nc = 0; while (getchar() != EOF) ++nc; printf("%ld\n", nc); }
    EOF indicates "end of file". A newline (which is what happens when you press enter) isn't the end of a file, it's the end of a line,
    so a newline doesn't terminate this loop.
     
    Last edited:
    • Like
    Reactions: 2020isuru