Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Curious about newline and carriage return

  1. #1
    Member
    Join Date
    May 2011
    Posts
    61
    My Mood
    Busy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Curious about newline and carriage return

    Hi, if I'm writing a Huffman code, I noticed that the text files online don't have a 1:1 relationship for total occurrances of new line with total occurrances of carriage return. I made a smalle text file and whenever I pressed the Enter key (I'm using Windows), I looked at the result and the newline appears the same number of times as the carriage return, which makes sense since a new line character cannot be produced without a carriage return character from pressing Enter key, so why do the web pages I created a huffman code with show the new line but no carriage return. So is it possible to create a new line character without using Enter to create a carriage return character?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Curious about newline and carriage return

    The two characters: "\n" and "\r" can either one or both be written to a file. Some editors will honor only one, some require both.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    May 2011
    Posts
    61
    My Mood
    Busy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Curious about newline and carriage return

    Quote Originally Posted by Norm View Post
    The two characters: "\n" and "\r" can either one or both be written to a file. Some editors will honor only one, some require both.
    I'm using the same text editor, so basically I'm comparing the space saved via Huffman vs ASCII, and I output how many times each alphabet shows up (0 - 255) and I noticed some webpages I copy (I included the HTML/JavaScript too as part of the text to build the Huffman tree) show the newline character without any carriage return, while others include newline character but there are carriage return, but the times the carriage return shows up is much less than the newline character, that's why I was curious so I thought it was possible for those people who wrote the webpages to use some program to never use the carriage return or something like that...because as I said in the OP, I created a new text file using the same text editor, and whenver I pressed Enter key, and when I ran the Huffman program I wrote, the total occurrances of the new line character matches the total occurrances of the carriage return character, since you need to press Enter in order for a new line character to be generated so still unsure

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Curious about newline and carriage return

    If the web pages are program generated, they don't need to use both characters. I wouldn't think too many pages were typed in using an editor.
    Last edited by Norm; November 25th, 2012 at 09:05 PM. Reason: fixed typo
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    May 2011
    Posts
    61
    My Mood
    Busy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Curious about newline and carriage return

    Ok, thanks for clarifying and btw, what do you mean *too pages*, is this just a typo?

Similar Threads

  1. Return Object does not return the expected output
    By Nour Damer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 13th, 2011, 07:24 AM
  2. Replies: 1
    Last Post: June 28th, 2011, 01:20 AM
  3. Replies: 2
    Last Post: February 14th, 2011, 02:32 AM
  4. how to return value ..
    By gr8mind in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 11th, 2011, 05:27 AM
  5. newLine isn't working
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 8th, 2011, 11:42 AM