What is the difference between Carriage Return and line feed?

Asked

Viewed 6,808 times

11

There are two different ways to break a CR line (Carriage Return) and LF (line feed).

What is the difference between these two? When should one or the other be used? Depends on the system? Language?

2 answers

15


As the name says the CR makes back to the beginning of the line and the LF is to go to the next line. Roughly it is the end of the line. This comes from the fact that printers worked like this.

In theory they should work independently and to go to the beginning of the next line should use both. But some systems have agreed to interpret only one of them as the intention to do both actions, even for space-saving purposes.

As with much in computing, it depends on who is interpreting. It is common to choose CR (Mac Os) or LF (Linux) or CR+LF (Windows) depending on the operating system because many of its tools have been made to interpret only one of these ways. But each tool can give you the semantics you want for this.

This is not to say that an operating system works with a terminator, only the tools available on it prefer or only accept a specific terminator. The best tools try to adapt.

In the background they are characters 13 and 10 of the ASCII table, so in various scenarios this does not mean anything with treatment of lines of text. Where there is a semantics in this sense, it has to see the documentation.

You can create a format that they are interpreted as you want. You can even use them to finish a line. It will only escape the pattern.

It depends on all this and is common when you will exchange text data between operating systems or even between specific tools.

Most languages have a way of abstracting the end-of-line indicator and it - via compiler or Runtime - is responsible for using the correct characters in each operating system.

Wikipedia.

0

For the purpose they were defined, in the primordial computer sciences, they represent literally printing commands. How everything was seen as an impression(including the output to the monitor) it was necessary to pass specific commands (used until today in many cases) format that would not be printed (visible to the user) but interpreted by the hardware (printer, monitor, etc.).

Practical example:

    1. Imagine a typewriter (old), the LF (line feed) would be the act of advancing a line, and the CR (Carriage Return) would be when you pull the car to the front page column.
    1. On a printer, it works in the same way: Upon receiving the print string it starts the job, upon realizing the LF during printing, it simply advances the line of the page keeping the printhead in the same place, upon realizing the CR she returns the printhead to the first column of the page.
    1. Practically the same thing happens in a terminal environment (console), LF jumps(advances) a line and CR turn the cursor to the beginning of the line.

In the end the difference is clear

  • LF (line feed): Break line, advance line or jump beautiful (as you wish).
  • CR (Carriage Return): Return cursor to first column.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.