使用for循环:

double count;
for(count = 0; getchar() != EOF; ++count)
     ;                                               /* null statement */
printf("%.0f\n", count);

使用while循环:

long count = 0;
while(getchar() != EOF)
   ++count;
printf("%ld\n", count);