[英]Don't understand the output for the character counting program
我刚开始学习c。 将 xcode 下载到我的 mac 并购买了 K&R 的 The c Programming Language。 我现在在字符计数部分,无法理解程序给我的输出。 程序是...
#include <stdio.h>
main()
{
long nc;
nc = 0;
while (getchar() !=EOF)
++nc;
printf("%ld\n", nc);
}
我从这些页面中了解到,我需要按 ctrl+d 两次才能向程序发送 EOF 字符,并且可以正常工作。 但是,它给我的答案是 140,734,799,804,376(逗号是我的)加上字符串中的字符数。 这个庞大的数字从何而来? 为什么程序不只返回 4 来表示“帮助”而不是 140734799804380?
nc = 0
和
++nc
此处缺少分号,更改为:
nc = 0;
++nc;
我尝试了这样的相同代码:
./test.exe
hello<CTRL+D>5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.