我从k&r第1.6章的程序示例中得到了错误的输出
我知道同一个例子还有另一个问题,但针对不同的问题。
这是代码示例:
#include /* count digits, white space, others */ main() { int c, i, nwhite, nother; int ndigit[10]; nwhite = nother = 0; for (i = 0; i = '0' && c <= '9') ++ndigit[c-'0']; else if (c == ' ' || c == '\n' || c == '\t') ++nwhite; else ++nother; printf("digits ="); for (i = 0; i < 10; ++i) printf(" %d", ndigit[i]); printf(", white space = %d, other = %d\n", nwhite, nother); }
运行之后是用程序执行程序 ,我得到:digits = 0 0 0 0 0 0 0 0 0 0,空格= 0,其他= 0.来自Xcode …
但在书中他们说“这个程序本身的输出是:digits = 9 3 0 0 0 0 0 0 0 1,white space = 123,other = 345”
你能告诉我发生什么事吗…知道。
从书中;
该程序本身的输出是
digits = 9 3 0 0 0 0 0 0 0 1,空格= 123,其他= 345
尝试使用自己的源作为输入;
> gcc test.c > ./a.out < test.c digits = 9 3 0 0 0 0 0 0 0 1, white space = 125, other = 345
关闭,但我怀疑StackOverflow的cut'n'paste可能占2个额外的空格:)