[Lab 03] File Size = Number of Characters + 1?

[Note] This message was posted on Forum 60-256 at Ataraxis (BBS ofComputer Sicence).

This is a discussion about Part 2 in Lab 03.

Many students find that the size of the test file is the number of characters in the test file plus 1, and there is an empty line between the original string and the reversed string in the output file.

Suppose we want to create a test file which contains a string "abc" ONLY, and we do it in three ways: using vi, using echo, and using cat.

1. create the test file "test1.txt" using vi;
2. create the test file "test2.txt" using echo; like this:
echo abc > test2.txt
3. create the test file "test3.txt" using cat;
For more info about how to use cat to create a new file, see this page.

Now use "ls -la test<1-3>.txt" to see the size of the files:

yin6@socr:~/test$ ls -la test<1-3>.txt
-rw-r--r-- 1 yin6 students 4 2005-02-10 23:59 test1.txt
-rw-r--r-- 1 yin6 students 4 2005-02-10 23:59 test2.txt
-rw-r--r-- 1 yin6 students 3 2005-02-10 23:59 test3.txt


We can see that using the first two methods, the test files contain an extra character (at the end of the file). The special character is a backspace character which was appended by the OS.

On some OS,the backspace character will output a new line, like what the new line character does.

That's why the size of the test file is the number of characters in the test file plus 1, and why there is an empty line between the original string and the reversed string in your output file.

类别:

添加新评论

友情提醒:您的言论自由在本站会得到充分保证;不过,由于广告留言等猖獗,因此本站的内容过滤系统有可能会暂时屏蔽您新发的留言或评论。不便之处,希望理解。