0

This sentence from k&r:

A text stream consists of a sequence of lines; each line ends with a newline character....For instance, the library might convert carriage return and linefeed to newline on input and back again on ouput.

How can you convert linefeed to newline and why is it done?

  • 3
    I think it says "carriage return and linefeed" to newline -> \r\n = \n. – Ouss4 Jun 25 '16 at 17:34
  • 1
    have you bothered to google for newline? – S.C. Madsen Jun 25 '16 at 17:34
  • The [\[ wiki article \]](http://stackoverflow.com/questions/4638552/carriage-return-in-c) says `This is why a newline in character encoding can be defined as LF and CR combined into one` – sjsam Jun 25 '16 at 17:38
  • 2
    Carriage return and line-feed are both terms which originated with the typewriter. Some systems continued the idiom over, while others said it was nonsense to continue to use a carriage return, when clearly, a new-line character was enough to signal that the cursor should return to the start of the next line. The conversion is needed to make both types of system play nicely together. It's done by simply adding or removing a \r character. – enhzflep Jun 25 '16 at 17:39
  • 1
    This [\[ answer \]](http://stackoverflow.com/a/3098328/1620779) has got all the information you need. – sjsam Jun 25 '16 at 17:49
  • @Ouss4 thanks for the clarification. – WizardOfRobots Jun 25 '16 at 18:06

0 Answers0