[ee122] [Question] CR and Newline
fowler at eecs.berkeley.edu
Thu Oct 18 19:06:47 PDT 2007
On 10/18/07, Jonathan D. Ellithorpe <jde at berkeley.edu> wrote:
> What is the difference between carriage return and newline?
> Should we be worried about using \r\n as the CRLF sequence? I've read
> that C doesn't guarantee that \r and \n map to the ASCII LF and CR
> control characters.
>From the RFC, in section 2.2, which is linked in the spec,
CR = <US-ASCII CR, carriage return (13)>
LF = <US-ASCII LF, linefeed (10)>
If you're worried about the \r and \n not mapping correctly, you can
use the ASCII representations.
A quick little wiki'ing says that "carriage return" historically moved
the printer "cursor" to the beginning of the line, whereas "line feed"
actually moves the paper, advancing the output to the next line.
Unfortunately the treatment of the two is inconsistent and often
causes problems (ever see lots of ^M's scattered through text
documents?)... So, since the spec doth declare that you must use CRLF
per their definitions of CR and LF, thou shalt use those definitions.
More information about the ee122