Microsoft KB Archive/29852

= How To Use fopen to Append Data to File Terminated w/ CTRL+Z =

Article ID: 29852

Article Last Modified on 7/13/2004

-

APPLIES TO

 The C Run-Time (CRT), when used with:  Microsoft C Professional Development System 5.1

 Microsoft C Professional Development System 6.0

 Microsoft C Professional Development System 6.0a

 Microsoft C Professional Development System 6.0a</li></ul>

 Microsoft C/C++ Professional Development System 7.0</li></ul>

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

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

 Microsoft Visual C++ 1.51</li></ul>

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

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

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

 Microsoft Visual C++ 2.1</li></ul>

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

-

<div class="notice_section">

This article was previously published under Q29852

<div class="notice_section">

<div class="summary_section">

SUMMARY
When data need to be appended to a stream file that is terminated with the CTRL+Z end-of-file (EOF) marker (ASCII 1Ah), use fopen with an access mode of &quot;a+&quot; to open the stream. This will ensure that all data appended to the stream are accessible after the stream is closed.

<div class="moreinformation_section">

MORE INFORMATION
If fopen is called with the &quot;a+&quot; mode, the operations of reading from and writing to the opened stream file are valid. Before any data are appended, the C Run-time reads the file and deletes the end-of-file marker. However, if fopen is called with the &quot;a&quot; mode, only the operation of writing to the opened file is valid. The C Run-time must seek to the end of the file and append characters after the end-of-file marker, CTRL+Z.

When displaying the contents of a text file, the MS-DOS and Windows NT TYPE commands stop upon encountering a CTRL+Z character. Certain editors such as Edlin and WordStar also ignore all characters after the first CTRL+Z in a file. Consequently, if text is appended after the CTRL+Z end-of-file marker, it may not be viewable.

Keywords: kbhowto kbcrt KB29852

-

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

© Microsoft Corporation. All rights reserved.