Unix To DOS/Windows

Unix To DOS/Windows
Philip J. Erdelsky
November 24, 2006
Public domain; no restrictions on use
Any C++ compiler for Windows XP
Unix, DOS, Windows
A simple utility which converts Unix text files to DOS/Windows text files by replacing \n with \r\n.

Unix text files and DOS/Windows text files are almost identical in format. Both use the ASCII character set. However, Unix puts a simple line feed character (\n) at the end of each line, but DOS/Windows puts both a carriage return (\r) and a line feed (\n) at the end of each line. This makes Unix files display incorrectly in some Windows/DOS utilities, such as the Notepad.

Some transfer utilities, such as FTP, will make the conversion automatically, but others will not. A simple conversion utility, running under Windows XP, is a great help.

The utility unix2dos.exe will make file conversions in place. It can be run in a DOS window with a command line of the following form:

unix2dos file1 file2 file3 ... file4

The specified files will be converted and the results will be written back to the same files. No backup copies are kept.

Under Windows XP, the utility can also be run without a DOS window. Just create a shortcut to the file unix2dos.exe and put it on the desktop. Then just drag one of more files and drop them on the shortcut. Windows XP will open a DOS window, run the utility, and then close the DOS window.

The utility will leave DOS/Windows line terminators unchanged, so if it is inadvertently applied to a file that is already in DOS/Waindows format, it will make no further changes.

The source code was compiled with Borland C++, but it should be compilable with other C++ compilers, too.