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

= June 6 =

Windows changing a text file automatically
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)


 * 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)