It is a feature of Windows going back to the first days of MS-DOS. In those systems, the convention is that a line delimiter is the character pair "\r\n
". Of course, in Linux/Unix/Solaris/etc., the line delimiter is the single character "\n
"
There are various utilities, such as Linux's dos2unix
and unix2dos
which do nothing but this transformation. Virtually every file transfer program has a means of dealing with it too. See kermit
's mode command.
The convention affected the MSDOS/windows C
runtime library function fopen()
(among others): the second parameter can have a b
or t
to explicitly set the line delimiter conversion. A t
ext conversion transforms \r\n
to \n
on input and \n
to \r\n
on output. A b
inary conversion does no such transformation.
FILE *f1 = fopen ("somefile.txt", "rt"); /* open in text conversion mode */
FILE *f2 = fopen ("anotherfile.bin", "rb"); /* open without text conversion */