今天,我编写了一段简单的代码,用于 getchar()计算您输入的字符数.但是当我在Cygwin上编译它时,它不起作用.它总是打印0,但我从不输入任何东西,或者我无法输入它打印的任何字符0.
但是,如果我使用VC++ 6.0编译它,它可以工作.
#include<stdio.h>
int main(void)
{
long nc;
nc = 0;
while(getchar() != EOF)
++nc;
printf("The total of characters you inputed is %ld.\n", nc);
return 0;
}
Run Code Online (Sandbox Code Playgroud)