The End of Line Puzzle

Back in the dark ages BC (Before Computers), there existed a magical device called a Teletype Model 33. This amazing machine contained a shift register made out of a motor and a rotor as well as a keyboard ROM consisting solely of levers and springs.

It contained a keyboard, a printer and a paper tape reader/punch. It could transmit messages over the phones using a modem at the blazing rate of 10 characters a second.

The Teletype had a problem. It took 2/10 second to move the printhead from the right side to the left. 2/10 second is two character times. If a second character came while the printhead was in the middle of a return, it was lost.

The Teletype people solved this problem by making end of line two characters: <carriage return> to position the printhead at the left margin, and <line feed> to move the paper up one line. That way the <line feed> "printed" while the printhead was racing back to the left margin.

When the early computers came out, some designers realized that using two characters for end of line wasted storage (at this time storage was very expensive). Some picked <line feed> for their end of line, some <carriage return>. Some of the die hards stayed with the two-character sequence.

UNIX uses <line feed> for end of line. The newline character '\n' is code 0xA (LF or <line feed>).

MS-DOS/Windows uses the two characters: <line feed><carriage return>. Compiler designers had a problem; what to do about the old C programs which thought that newline was just <line feed>? The solution was to add code to the I/O library that stripped out the <carriage return> characters from ASCII input files and changed <line feed> to <line feed> <carriage return> on output.