Why doesn’t this code do anything when i execute it? It’s supposed to count characters
i even pressed ctrl+z which someone suggested and it still wont print how many characters after i entered random things. I’m using windows btw
#include <stdio.h>
int main()
{
long nc;
nc = 0;
while (getchar() != EOF)
++nc;
printf("%ld\n", nc);
return 0;
}
It works if you press
CTRL+Zand then enter. This triggersEOF.If you want it to end when you press enter, use