[英]Why does my linked list only contain one node even though I added more than one?
[英]Why does the file created using a text editor contain one byte more than expected?
我創建了一個這樣的文件
av bb e
在最后一行輸入e
之后我沒有按enter
鍵。
所以第一行'a',' ','v','\\n'
有四個字符。
第二行'b','b','\\n'
有三個字符。
最后一行'e'
有一個字符。
所以這個文件中總共有8個字符。 但是當我使用以下C程序計算字符時:
#include<stdio.h>
/* count characters in input; 1st version */
int main()
{
long nc;
nc = 0;
while (getchar() != EOF) {
++nc;
}
printf("%ld\n", nc);
return 0;
}
它給了我9.即使我使用wc
命令計數,它仍然是9.為什么?
有理由支持使用換行符終止所有行:
還有一些文本編輯器設置為自動添加尾隨換行符(如果還沒有):
可能這就是您觀察到意外文件大小的原因。
要檢查這些文件的實際內容,我喜歡使用hexdump
:
$ hexdump -C test
00000000 61 20 76 0a 62 62 0a 65 0a |a v.bb.e.|
00000009
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.