How To Use fopen() to Append Data to File Terminated w/ CTRL+Z (29852)
The information in this article applies to:
- The C Run-Time (CRT), when used with:
- Microsoft C for MS-DOS 5.1
- Microsoft C for MS-DOS 6.0
- Microsoft C for MS-DOS 6.0a
- Microsoft C for MS-DOS 6.0ax
- Microsoft C/C++ for MS-DOS 7.0
- Microsoft Visual C++ 1.51
- Microsoft Visual C++ 1.52
- Microsoft Visual C++, 32-bit Learning Edition 4.0
- Microsoft Visual C++, 32-bit Professional Edition 2.0
- Microsoft Visual C++, 32-bit Professional Edition 2.1
- Microsoft Visual C++, 32-bit Professional Edition 4.0
This article was previously published under Q29852 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 "a+" to open the stream. This will ensure that
all data appended to the stream are accessible after the stream is
closed.
MORE INFORMATION
If fopen() is called with the "a+" 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 "a"
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.
Modification Type: | Minor | Last Reviewed: | 7/13/2004 |
---|
Keywords: | kbCRT kbhowto KB29852 |
---|
|