Carriage return and line change

Today, I've finally figured out the difference between the concepts of carriage return and line feed.

Before computers existed, there was a Teletype Model 33 that could type 10 characters per second. But it had the problem that it took 0.2 seconds to type exactly two characters after a line feed. If a new character comes in during those 0.2 seconds, that character will be lost.

So, the developers thought of a way to solve this problem, that is, in each line after the addition of two characters that end. One is called "Enter", tell the typewriter to position the print head in the left border; the other is called "line feed", tell the typewriter to move the paper to the next line.

This is the origin of the words "line feed" and "carriage return", which can also be seen in their English names.

Later, when the computer was invented, these two concepts were applied to computers as well. At that time, memory was very expensive, and some scientists thought that adding two characters at the end of each line was too wasteful, so adding one would do. So, there was a disagreement.

In Unix system, each line ends with "<new line>", that is, "\n"; in Windows system, each line ends with "<return> <new line>", that is, "\r\n"; in Mac system, each line ends with "<return>". A direct consequence is that when a file under Unix/Mac system is opened in Windows, all the text will become one line; when a file in Windows is opened in Unix/Mac system, there may be an extra ^M symbol at the end of each line.

Leave a Reply

Your email address will not be published. Required fields are marked *