Re: K&R2 2.3 : /n vs /r

From: Kurt Watzka (watzka_at_stat.uni-muenchen.de)
Date: 10/20/04


Date: Wed, 20 Oct 2004 18:06:06 +0200

john blackburn wrote:

> Merrill & Michele wrote:
>
>> Section 2.3 of K&R enumerates the complete set of escape sequences.
>>
>> Q1) Is it possible to ask the following question without getting into
>> implementation/platform talk?
>>
>> Q2) What on earth is the difference between newline and carriage return?
>>
>> MPJ
>
> '\r' is simply a carriage return whereas '\n' is a carriage return
> followed
> by line feed.

Well, from the persprective of this newsgroup, this is certainly wrong.
'\r' is a carriagge return, '\n' is a newline character. From a C
programmers point of view, '\n' is _the_ line separator.

> Note that a carriage return is simply that, it moves the
> cursor to the beginning of the current line and does not move on to the
> next line.
>
> It is here you have to be careful as UNIX text files are of a different
> format from Windows text files and need conversion when moving from one
> o/s to the other.

On a T200 teletype you had to be carefull to always use _two_ carriage
returns and a linefeed at 75 baud, because the time to move the carriage
from the leftmost position to the rightmost position took almost 1/25
of a second. With '\r\n' you would end up with the first character of
the new line in the middle of the line. However, this is about as relevant
to text file formats from a C programming point of view as the different
_physical_ representations of line separators used in different
environments.

Kurt Watzka



Relevant Pages

  • Re: Different file defaults for Tcl 8.4?
    ... note that the carriage returns are converted to newline. ... This behavior is expected with Windows, but not with Unix. ... As the input translation mode, auto treats any of newline, carriage return, or carriage return followed by a newline as the end of line representation. ...
    (comp.lang.tcl)
  • Re: zsh prompt
    ... >>I see that one can put a newline in the prompt and set an option to diabled the ... >> carriage return. ... but my prompt ending up looking like that string exactly. ... Where can I read to learn about that type of syntax? ...
    (comp.unix.shell)
  • Re: Parsing a text file line-by-line: skipping badly-formed lines?
    ... perlvar manpage), $ln contains newline-terminated records, so ... followed by a newline at the end of $ln. ... in a followup farther downthread, ... that's being ignored because it doesn't have a carriage return. ...
    (comp.lang.perl.misc)
  • Re: A bit of good news in May
    ... Carriage Return/Line Feed Dash Dash Space Carriage Return/Line Feed ... In other words the Sig Separator is 2 Dashes, ... Its first newline is part of the body text, ... Even if there's nothing after the NewLine Character? ...
    (uk.people.silversurfers)