Today's Question:  What's your opinion about Alibaba mooncake incident?        GIVE A SHOUT

Technical Article => Other =>  Other

Carriage return and line feed

  Peter      2012-05-18 11:12:55      7,734    0    0

In programming and document editing, we may frequently encounter carriage return and line feed, i.e the well known CRLF.  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 characters is transferred during this 0.2 second, then this new character will be lost.

So scientists found a way to solve this problem, they add 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, one is 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 : http://www.ruanyifeng.com/blog/2006/04/post_213.html

CR CARRIAGE RETURN LINE FEED LF NEW LINE

  SAVE AS PDF   MARK AS READ   MARK AS IMPORTANT

  RELATED


  0 COMMENT


No comment for this article.


  WRITE ARTICLE

Consequence of a sudden state change

By sonic0002