Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
#include <stdio.h> int main(int argc, const char * argv[]) { long nc; nc=0; while (getchar()!=EOF) { ++nc; printf("%ld\n", nc); } }
这是代码,当我输入一个字符时,它会先打印 1,然后再打印 2,即使我只输入了一次。
我正在使用 Xcode。
但你确实按下return了,不是吗?尝试按CTRL+D或注意循环中的换行符。也许是这样的?
return
int ch; while ((ch = getchar()) != EOF) { if (ch == '\n') continue; ++nc; printf("%ld\n", nc); }