About /r and /n...

This is a discussion on About /r and /n... within the C++ Programming forums, part of the General Programming Boards category; So I know that /n is a newline, and /r is a carriage return. But what exactly are they used ...

  1. #1
    Geek. Cobras2's Avatar
    Join Date
    Mar 2002
    Location
    near Westlock, and hour north of Edmonton, Alberta, Canada
    Posts
    113

    About /r and /n...

    So I know that /n is a newline, and /r is a carriage return. But what exactly are they used for, and who uses them?
    If you have a newline what is the point of a Carriage Return?
    And where and when should you use both /r/n, and when can you use just /n ?
    Do all OSs use them in text files and the like? or is it much more specific than that?

    --edit--
    oh and if anyone has just a reference about them, plz point me that way, because I can't find much about them in my C++ reference book ("The Complete Reference C++, Third Edition" by Herb Shildt)
    Last edited by Cobras2; 03-03-2003 at 07:05 PM.
    James G. Flewelling
    Rgistered Linux User #327359
    Athabasca University Student (BSc. CIS)

    http://catb.org/~esr/faqs/smart-questions.html
    http://catb.org/jargon/

    http://www.ebb.org/ungeek
    ---GEEK CODE---
    Version: 3.12
    GCS/IT/M d- s+:++ a-->->>+>++>+++>? C++++>$ UL++>++++$ P++>++++ L++>++++$
    E W++ N o? K? w++(--)>--- O? M? V? PS--(---) PE Y+ PGP? t 5? !X R(*)>++
    tv-->! b++(+++)>++++ DI? D+++(---)>++++$ G e*>++$ h++>*$ r!>+++ y?
    ----/GEEK CODE----
    upd: 2005-02-11

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    A carriage return moves the cursor back to the first column. A new line moves the cursor down a line. With most console programs, \r is not needed since the cursor defaults to the home column whenever there is a new line. With my socket class, I had to be sure to include a carriage return every time I had a new line or else the cursor would be one line under where it was before instead of in home column.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    Geek. Cobras2's Avatar
    Join Date
    Mar 2002
    Location
    near Westlock, and hour north of Edmonton, Alberta, Canada
    Posts
    113
    Oh! I see.. ok, that's very interesting. Can be pretty useful too.. I wonder why they bothered making consoles default to the home line..? anyway thanks for that, it helps
    James G. Flewelling
    Rgistered Linux User #327359
    Athabasca University Student (BSc. CIS)

    http://catb.org/~esr/faqs/smart-questions.html
    http://catb.org/jargon/

    http://www.ebb.org/ungeek
    ---GEEK CODE---
    Version: 3.12
    GCS/IT/M d- s+:++ a-->->>+>++>+++>? C++++>$ UL++>++++$ P++>++++ L++>++++$
    E W++ N o? K? w++(--)>--- O? M? V? PS--(---) PE Y+ PGP? t 5? !X R(*)>++
    tv-->! b++(+++)>++++ DI? D+++(---)>++++$ G e*>++$ h++>*$ r!>+++ y?
    ----/GEEK CODE----
    upd: 2005-02-11

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    It's \r and \n, and I suggest you burn that Schildt book and get one by someone who isn't an idiot.

  5. #5
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Location
    Mt. Prospect, IL
    Posts
    2,572
    makes you wonder why he still keeps gatting book deals?!

    axon

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  6. #6
    still a n00b Jaguar's Avatar
    Join Date
    Jun 2002
    Posts
    187
    As I tried.
    An `ENTER' key is treated as \r for WIN/DOS
    but
    An `ENTER' key is treated as \n for Linux (at least Redhat)
    slackware 10.0; kernel 2.6.7
    gcc 3.4.0; glibc 2.3.2; vim editor
    migrating to freebsd 5.4

  7. #7
    Geek. Cobras2's Avatar
    Join Date
    Mar 2002
    Location
    near Westlock, and hour north of Edmonton, Alberta, Canada
    Posts
    113
    I see.. I had never heard before that Schildt didn't know what he was talking about.
    lol.. /r.. I think I've been switching back and forth between linux and windows too much recently..
    I keep using the wrong / or \
    Anyway, I never have used just the one book as my only reference, I've always supplemented it
    with other things(from the web mostly) - but it's too bad I didn't find out about that before
    I bought the book like a year ago.. oh well..
    One question though.. if Schildt doesn't know what he's talking about how'd he end up on the ISO comittee?
    Is it really that much influenced by how popular someone's books are?
    James G. Flewelling
    Rgistered Linux User #327359
    Athabasca University Student (BSc. CIS)

    http://catb.org/~esr/faqs/smart-questions.html
    http://catb.org/jargon/

    http://www.ebb.org/ungeek
    ---GEEK CODE---
    Version: 3.12
    GCS/IT/M d- s+:++ a-->->>+>++>+++>? C++++>$ UL++>++++$ P++>++++ L++>++++$
    E W++ N o? K? w++(--)>--- O? M? V? PS--(---) PE Y+ PGP? t 5? !X R(*)>++
    tv-->! b++(+++)>++++ DI? D+++(---)>++++$ G e*>++$ h++>*$ r!>+++ y?
    ----/GEEK CODE----
    upd: 2005-02-11

  8. #8
    Geek. Cobras2's Avatar
    Join Date
    Mar 2002
    Location
    near Westlock, and hour north of Edmonton, Alberta, Canada
    Posts
    113
    eek - schildt even made it into the jargon file..? not exactly an entry to be proud of. I guess it just shows to go that I never read that far through the jargon file in a straight line tho heh.. man that is an interesting document.
    Anyway,
    > As far as I know, he's only an observer

    Ah, okay.. I thought I had read somewhere he was actually on the committee

    Yes indeed - I believe Hitler said something about "Say something loud enough and long enough, and it doesn't matter what it is, people will believe it."
    Seriously, though, for the most part I use the book as a reference to the standard functions, which he has a list in the back - I haven't actually *read* very much of it except some stuff on file i/o and pointers - that book has actually been extremely useful to me on some things.. for instance pointers.. although any other book on the subject would most likely have been just as (or more) useful. At least he doesn't tell you to use void main in this one.. ^.^
    James G. Flewelling
    Rgistered Linux User #327359
    Athabasca University Student (BSc. CIS)

    http://catb.org/~esr/faqs/smart-questions.html
    http://catb.org/jargon/

    http://www.ebb.org/ungeek
    ---GEEK CODE---
    Version: 3.12
    GCS/IT/M d- s+:++ a-->->>+>++>+++>? C++++>$ UL++>++++$ P++>++++ L++>++++$
    E W++ N o? K? w++(--)>--- O? M? V? PS--(---) PE Y+ PGP? t 5? !X R(*)>++
    tv-->! b++(+++)>++++ DI? D+++(---)>++++$ G e*>++$ h++>*$ r!>+++ y?
    ----/GEEK CODE----
    upd: 2005-02-11

  9. #9
    ! |-| /-\ +3 1337 Yawgmoth's Avatar
    Join Date
    Dec 2002
    Posts
    187
    Originally posted by Cobras2


    Yes indeed - I believe Hitler said something about "Say something loud enough and long enough, and it doesn't matter what it is, people will believe it."
    By means of shrewd lies, unremittingly repeated, it is possible to make people believe that heaven is hell -- and hell heaven. The greater the lie, the more readily it will be believed.
    Adolph Hitler, Mein Kampf
    L33t sp3@k sux0rz (uZ it t@k3s 10 m1|\|ut3s 2 tr@nzl@te 1 \/\/0rd & th3n j00 h@\/3 2 g3t p@$t d@ m1zpelli|\|gz, @tr0(i0u$ gr@mm@r @|\|d 1n(0/\/\pr3#3|\|$1bl3 $l@|\|g. 1t p\/\/33nz j00!!

    Speling is my faverit sujekt

    I am a signature virus. Add me to your signature so that I may multiply.

  10. #10
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    Getting back to the point...

    \r\n is used in a lot of DOS text files and console input/output. The carriage return was used back in the time where terminals didn't know enough to do that after each line. Because DOS is so old, it inherited this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help writing a program
    By alex1067 in forum C Programming
    Replies: 18
    Last Post: 04-04-2008, 11:33 PM
  2. Remove new line (/n) from string
    By 3saul in forum C Programming
    Replies: 3
    Last Post: 01-23-2006, 02:32 PM
  3. PIC16F876 's USART
    By Tombear in forum C Programming
    Replies: 4
    Last Post: 04-19-2002, 08:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21