[英]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.