Count Characters on STDIN

  • If in the while loop there is only one statement, we don't need to put it in curly braces. I don't really like this, but this is how C is.

#include<stdio.h>

int main() { long count = 0;

while (getchar() != EOF)
    count++;

printf("Number of characters: %ld\n", count);

return 0;

}