Microsoft KB Archive/51665
Using a CTRL+Z Character to Terminate Text Files ID Number: Q51665
1.x 2.x 3.00 3.10 3.20 3.21 3.22 3.30 4.00 4.01 MS-DOS
If you are writing a program that creates ASCII text files, which users may want to view with a file lister or editor that you didn’t write you must make a decision of whether or not to terminate the ASCII text files with a CTRL+Z character. This article addresses this issue.
A CTRL+Z character is ASCII mnemonic SUB, with a value of 1AH. Using a CTRL+Z character to end a text file is a good idea. The main reason for this is that there are some popular old text editors around that get confused if there isn’t a CTRL+Z character at the end of the file. Most recent versions of these programs do not put such restrictions on your files; however, compatibility is always an issue. In MS-DOS Versions later than 2.x, this is not as important as it is in Version 2.x.
The most robust way for your application to create text files is to allow the user to configure your application, so that the user can make this decision. You can do this via any of the following mechanisms:
- Command-line arguments
- Environment variables
- Initialization files
- An installation program that modifies your application
For example, you could have the application default to not placing a CTRL+Z character at the end of a file, unless the user explicitly configures your program to do this.
Other operating systems may have similar problems with files that do or don’t have this character in it. The MS-DOS COPY command has switches to allow users to concatenate multiple text files that are terminated with a CTRL+Z character into a single text file with no CTRL+Z characters in it.
In summary, it is preferable to have the ability to configure your application so that it can write a CTRL+Z character at the end of a text file (for compatibility with older software). However, these days, most applications don’t require the presence of this character at the end of the file. The best way is to let the user make this decision.