Microsoft KB Archive/68423

= INFO: The Use of a CTRL+Z Is Limited in Text Files =

Article ID: 68423

Article Last Modified on 12/12/2003

-

APPLIES TO

 The C Run-Time (CRT), when used with:  Microsoft Visual C++ 1.0 Professional Edition

 Microsoft Visual C++ 1.5 Professional Edition

 Microsoft Visual C++ 1.0 Professional Edition

 Microsoft Visual C++ 2.0 Professional Edition</li></ul>

 Microsoft Visual C++ 4.0 Standard Edition</li></ul>

 Microsoft Visual C++ 5.0 Standard Edition</li></ul>

 Microsoft Visual C++ 6.0 Service Pack 5</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q68423

<div class="notice_section">

<div class="summary_section">

SUMMARY
In Microsoft C/C++, the use of a CTRL+Z (hex 1A, decimal 26) is limited in a file opened in text (translated) mode. If a file contains a CTRL+Z, there can be only one occurrence of it and it must be the last character in the file.

No other instance of a CTRL+Z is allowed in text mode. By using multiple CTRL+Zs, or by having characters after the CTRL+Z, you may cause fseek, or run-time functions that call fseek, to behave in an unexpected manner. By using one of the following, these functions will perform as expected if you have multiple CTRL+Zs in the file.  Open the file in binary (untranslated) mode.

-or-

</li> Convert your input file to meet the previously mentioned conditions of a text file.</li></ul>

When opening a file in binary mode, you must remember that the file is untranslated. This means that on input, the carriage return-linefeed (CR- LF) combination is not translated into a single linefeed (LF) character, and on output, the (LF) character is not translated into a (CR-LF) combination.

This may necessitate modifications to your I/O routines that deal with newlines (\n) and carriage returns (\r).

Examples of Opening Binary Files
The following opens a file called FILENAME.DAT for both reading and writing in binary mode: FILE * fileptr; fileptr = fopen( &quot;filename.dat&quot;, &quot;rb+&quot;); The letter &quot;b&quot; in the access mode designates opening for binary mode.

The following opens a file called FILENAME.DAT for both reading and writing in binary mode. int filehndl; filehndl = open( &quot;filename.dat&quot;, O_CREAT | O_BINARY | O_RDWR,                                   S_IWRITE | S_IREAD); The O_BINARY constant designates the file to be opened in binary mode.

With both of the file-open commands, it should be noted that the text (translated) mode is the default mode. You may link with an object module called BINMODE.OBJ to change the default mode to binary. This file is located in your LIB subdirectory.

This is expected behavior for the Microsoft C/C++ Compiler.

Keywords: kbinfo kbcrt KB68423

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.