There are two different ways to break a CR (carriage return) line and LF (line feed).)
What's the difference between these two? When should one use one or the other? Does it depend on the system? From the language?
There are two different ways to break a CR (carriage return) line and LF (line feed).)
What's the difference between these two? When should one use one or the other? Does it depend on the system? From the language?
As the name says the CR returns to the beginning of the line and the LF is to go to the next line. Roughly it's the end of the line. This comes from the fact that the printers worked like this.
In theory, they should function independently and to go to the beginning of the next line should use both. But some systems agreed to interpret only one of them as intending to do both.
As with much computing, it depends on who you are playing. It is common to choose CR (Mac Os) or LF (Linux) or CR + LF (Windows) depending on the operating system because many tools of it were made to interpret in only one of these ways. But each tool can give you the semantics you want for it.
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 the characters 13 and 10 of the ASCII table, so in many scenarios this does not mean anything with handling lines of text. Where there is a semantics in this sense, you have to see the documentation.
You can create a format that they interpret as you want. They can not even use them to finish a line. It will only escape the pattern.
It depends on all of this and is common when you are exchanging 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 - takes care of using the correct characters in each operating system.