"new line" character - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

"new line" character

hey there...

i've noticed something seemed strange to me...
if anyone just open the Notepad and type just ONE "Enter" , and if you save the .txt file and check its size, you will notice that its size is TWO bytes... but why???
i know that, in c++,u can store the new line '
' in a single byte character... but when i checked the ASCII character set, i've noticed that there isn't a single character representing the new line...
there are the LF and CR characters, but what does this characters exactly means? and what happens really in notepad??

thanks
ak

Comments

  • VilanyeVilanye Posts: 684Member
    0xD is the ascii value for carriage return.

    I believe the reason your .txt file is 2 bytes is because of the carriage return and end of file marker.

    : hey there...
    :
    : i've noticed something seemed strange to me...
    : if anyone just open the Notepad and type just ONE "Enter" , and if you save the .txt file and check its size, you will notice that its size is TWO bytes... but why???
    : i know that, in c++,u can store the new line '
    ' in a single byte character... but when i checked the ASCII character set, i've noticed that there isn't a single character representing the new line...
    : there are the LF and CR characters, but what does this characters exactly means? and what happens really in notepad??
    :
    : thanks
    : ak
    :

  • happy_84khappy_84k Posts: 106Member
    : 0xD is the ascii value for carriage return.
    :
    : I believe the reason your .txt file is 2 bytes is because of the carriage return and end of file marker.
    :

    hey man...

    but i think there is no 'end of file marker',
    try to save a new file without typing anything in it.
    its size would be Zero!!!!

    thanx
    ak

  • stoberstober Posts: 9,765Member ✭✭✭
    The end-of-line markers depend on the operating system.

    MS-DOS/Windows: Carriage Return/Line Feed, often CR/LF, which is two characters. If the file is opened in text mode, C/C++ compilers translate '
    ' into "
    " pair before writing them out to the file, and translate "
    " to "
    " when reading them back. When the file is opened in binary mode, no translation takes place.

    *nix (Unix and Linux): end-of-line marker is "
    ", with no translation in either text or binary mode.

    MAC: end-of-line marker is "
    ". I suspece (but don't know for a fact) that "
    " is translated into "
    " when read, to maintain c/c++ standards.
  • shaolin007shaolin007 Posts: 1,018Member
    : hey there...
    :
    : i've noticed something seemed strange to me...
    : if anyone just open the Notepad and type just ONE "Enter" , and if you save the .txt file and check its size, you will notice that its size is TWO bytes... but why???
    : i know that, in c++,u can store the new line '
    ' in a single byte character... but when i checked the ASCII character set, i've noticed that there isn't a single character representing the new line...
    : there are the LF and CR characters, but what does this characters exactly means? and what happens really in notepad??
    :
    : thanks
    : ak
    :
    Mine says 3 bytes and under a hex editor it shows why.

    [code]
    31 0d 0a
    [/code]
    0d & 0a take each a byte in memory carraige return and line feed.
  • viki007viki007 Posts: 46Member
    : hey there...
    :
    : i've noticed something seemed strange to me...
    : if anyone just open the Notepad and type just ONE "Enter" , and if you save the .txt file and check its size, you will notice that its size is TWO bytes... but why???
    : i know that, in c++,u can store the new line '
    ' in a single byte character... but when i checked the ASCII character set, i've noticed that there isn't a single character representing the new line...
    : there are the LF and CR characters, but what does this characters exactly means? and what happens really in notepad??
    :
    : thanks
    : ak
    :

    once i broke "Enter" into 2 symbows and they looked like squares seperately but when i put one in front of the other they turn into an enter and that looks strange... i mean u put something if front of a symbow and it turns into an enter lol...i could actualy use them as any other symbow (copy and paste them wherever i want)

    [hr]
    by viki007

Sign In or Register to comment.