Article ID: 268901 - View products that this article applies to.
This article was previously published under Q268901
When you edit source files in Visual C++ and save them, the lines are terminated with the "CR/LF" [carriage return, line feed] character combination. On UNIX systems, lines are terminated by "LF". So, when you view files that were edited under Windows on UNIX systems you may see many "^M" characters terminating the lines. This happens if the editor you are using doesn't know how to interpret the Windows file. Visual C++ can open files that have lines that terminate with the UNIX-created LF. If you edit this file and save it from Visual C++ then it is saved in the Windows format (you will see CR/LF and not the LF that was present previously).
This article describes a procedure for saving an edited file created on a Windows platform in a format that can be used on UNIX systems.
NOTE: The Visual C++ .NET IDE has a feature available to save a file in UNIX format. In IDE, save the file using Save As..., from the Save drop-down list, select Save with Encoding..., and thrn click Yes. From the Line Encoding drop-down list, select Unix (LF), and then click OK.
You can use the following steps to create a Win32 console project that will convert a file containing "CR/LF" for line termination to "LF":
48 65 6C 6C 6F 0D 0A 57 6F 72 6C 64This is equivalent to:
HelloFrom a command prompt, run the command dos2unix.exe <file name>. Next, open the file in the Visual C++ binary editor. You will see that the 0x0Ds are removed. As long as you don't edit the file and save it in Visual C++ the 0x0Ds will not appear.
You can use this in conjunction with Visual C++ automation to automate the entire process. A simple Microsoft Visual Basic Script macro can be written to call this tool, but first this tool must be added to the Tools menu as follows:
If you want to automate this process so that every time you save an opened file in the Visual C++ editor, the DOS2UNIX.exe tool is called to remove the 0x0Ds, then use the following VBScript macro:
This VBScript code will work only if you have a file open in the Visual C++ editor. This is the only way to call an .exe file from a VBScript macro (you cannot pass parameters to a VBScript macro). You can write an add-in instead, and this would be more flexible. You can call the DOS2UNIX.exe tool from an add-in without having to add it to the Tools menu.
To use the provided VBScript macro in Visual C++:
If you are using Microsoft Visual SourceSafe as the source code management tool, then see the following Knowledge Base article:
(http://support.microsoft.com/kb/170750/EN-US/ )INFO: End of Line Character Settings for Visual SourceSafe
For more information see "Developer Studio Objects" in the MSDN Library:
http://msdn.microsoft.com/en-us/library/aa242803(VS.60).aspxAlso see "Argument Macros":
Article ID: 268901 - Last Review: July 13, 2004 - Revision: 3.2
Contact us for more help