Wikipedia:Reference desk/Archives/Computing/2015 June 6

From Wikipedia, the free encyclopedia
Computing desk
< June 5 << May | June | Jul >> June 7 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


June 6[edit]

Windows changing a text file automatically[edit]

If you open a plain text file using some Windows program just for reading, can it be that this program changes the newline character to its own form and saves this change, (\n > \r\n)? Or, does it just add an \r before the \n afor its own internal processing nd leaves the file alone? Does Windows change anything else when in text mode, when reading or writing to a plain text file? --YX-1000A (talk) 17:10, 6 June 2015 (UTC)[reply]

Windows, as such, doesn't have a concept of text files. How a particular program handles text files is up to that program.
The most common approach to newlines on Windows is actually to remove \r characters when reading, treat \n as the line separator internally, and add \r before every \n when writing. This is a hack dating back decades whose purpose was to ease porting of C software from UNIX to DOS, but which later was enshrined in the C standard, was adopted by other languages, and is apparently never going to die.
A better approach, used by Notepad++ and many other programmers' editors, is to leave the data untouched and recognize all the newline conventions internally.
Regardless, it would be quite rude to modify a file that you opened only to read and never saved. I can't rule out that some software does that, but most won't -- BenRG (talk) 17:31, 6 June 2015 (UTC)[reply]