Today's Question:  What are you most afraid of as a programmer?        GIVE A SHOUT

Technical Article => Programming =>  Programming

Carriage return and line feed

  Peter      2017-02-19 08:29:23      9,956    0    0

In programming and document editing, we may frequently encounter carriage return and line feed, i.e the well known CRLF.  But do you know about the history and difference of carriage return and line feed?

Before computer came out, there was a type of teleprinter called Teletype Model 33. It can print 10 characters each second. But there is one problem with this, after finishing printing each line, it will take 0.2 second to move to next line, which is time of printing 2 characters. If a new character is transferred during this 0.2 second, then this new character will be lost.

So scientists found a way to solve this problem, they added two ending characters after each line, one is 'Carriage return', which is to tell the printer to bring the print head to the left; the other one is 'Line feed', it tells the printer to move the paper up 1 line.

Later, computer became popular, these two concepts are used on computers. At that time, the storage device was very expensive, so some scientists said that it was expensive to add two characters at the end of each line and they thought one was enough, so there are some arguments about which one to use.

In UNIX, '\n' is put at the end of each line, in Windows, '\r\n' is put at the end of each line, while in Mac, '\r' is put at the end of each line. The consequence of this use is that files in UNIX/Mac will be displayed in one line if opened in Windows. While file in Windows will have one ^M at the end of each line if opened in UNIX or Mac.

Original author : 阮一峰  Source :



Share on Facebook  Share on Twitter  Share on Google+  Share on Weibo  Share on Reddit  Share on Digg  Share on Tumblr    Delicious



No comment for this article.


Pair programming

By sonic0002