EOF detection in console

Trips

Well-known member
Joined
Aug 7, 2010
Messages
2,788
Hi, I am new to Visual Studio.  My question is that I am trying to detect EOF in the console, but control+D doesnt seem to work...neither does control+D followed by <Enter>...i.e., with a small code snippet such as this:

#include <stdio.h>

main () {
    long nc;

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

Could anyone help please?

Thank you,

Signed,
Forever Dumb


View the full article
 
Back
Top