ANSWERS: 3
  • They're all different ways of signaling a new line. Windows prefers to use CR and LF. Unix systems prefer just LF. It rarely causes compatibility problems these days, though. In Java, whenever I want a new line, I use the "backslash n" escape sequence.
  • Line Feed (LF) and New Line are the same thing, Ascii code 10 and indicated in Java by n. Carriage Return (CR), Ascii code 13, is indicated by r. The Enter key usually generates LF. On early teletypes, the two operated independently. Carriage Return only moved the head back to the left margin, so that without further action it would overwrite the data previously typed. Line Feed only moved the paper up one line, so that you just got a jog in the line. To accomplish the new line effect, you therefore needed both. They had to be in the order CR-LF, because the CR took quite a long time, and if you didn't do it first, the first printing character of the next line would come out before the head had flown all the way back (in fact, this would sometimes happen on very long lines even if you did put LF second, so the safest thing was to do CR/LF/NUL/NUL). Because the earliest "type" commands simply copied the raw data to the teletype, some OS-es adopted the convention of putting CR/LF into the file at the end of every line. Other OS-es took the opposite convention of just putting LF into the file, and expanding that if necessary to CR/LF on output.
  • Line Feed and Carriage Return are holdovers from the days of carriage driven form-fed printers. You can think of it as being like a type writer. Line feed caused the printer to feed out the paper just a bit more so that printing would occur on a new line, and carriage return would return the carriage to its starting position so that the next character printed would be aligned to the left of the paper. (I don't expect it was exactly the same as a type writer, but the same process held to some extent.) Because of this process, carriage returns and line feeds usually came together and some pograms today still expect them like that. We don't print that way anymore and the distinction between the two characters has become somewhat obsolete. This has given rise to some minor variety in the way programs indicate line breaks and the way they expect line breaks to be indicated. Most programmers simply insert a "newline" ("n"). See the Wikipedia article here: ( http://en.wikipedia.org/wiki/Newline ) The newline is not a distinct character. I generally used to consider that this was equivalent to a line feed character, but such is apparently not always the case.

Copyright 2023, Wired Ivy, LLC

Answerbag | Terms of Service | Privacy Policy