why the text file size is one more than the character count

Hi all:

i have a file which contains 332 characters determined by using the document statistics feature of gedit, but actually its file size on disk is 333 bytes from ls -lh output ? so, what is the reason ? At first glance,it seems related to the EOF character at the end of file which adds one more to the file size,well,from the

http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?id=1043284351&answer=1048865140

,it says EOF is not a char. Now,i am totally befuddled.

thanks in advance !
Last edited on
Run your file through the od utility. You will see all of the characters that way. I suggest:

1
2
3
4
5
6

man od     (To find out about od)

cat yourfile | od -x  (To see your file's contents)

 
thank you for the reply.

it turns out that the extra byte is 0a,and i also have a discovery that if you open gedit or nano text editor,type character '1' and '2' ,save the file as haha or any name you like. use the command cat haha | od -x,and you will see

0000000 3231 000a
0000003


i make sure that i did not press the enter key,but always there is an extra 0a byte,a line feed character looked up from the ascii character map. i really want to know the reason.

thanks a lot
Most editors will add the newline character (0xA) to the end of the file. BTW, there is no EOF character; EOF is returned from file reading functions when they detect the end of the file.
yes,now i get the point . thanks a lot !
Last edited on
Topic archived. No new replies allowed.