Can we write an EOF character ourselves?

Apoorv Saxena picture Apoorv Saxena · Jun 17, 2010 · Viewed 87.2k times · Source

Most of the languages like C++ when writing into a file, put an EOF character even if we miss to write statements like :

filestream.close

However is there any way, we can put the EOF character according to our requirement, in C++, for an instance. Or any other method we may use apart from using the functions provided in C++.

If you need to ask more of information then kindly do give a comment.

Thanks in advance.

EDIT: Thanks for your support but here's an addition to this question:

What if, we want to trick the OS and place an EOF character in a file and write some data after the EOF so that an application like notepad.exe is not able to read after our EOF character. I have read answers to the question related to this topic and have come to know that nowdays OS generally don't see for an EOF character rather check the length of file to get the correct idea of knowing about the length of the file but, there must be a procedure in OS which would be checking the length of file and then updating the file records.

I am sorry if I am wrong at any point in my estimation but please do help me coz it can lead to a lot of new ideas.

Answer

ypnos picture ypnos · Jun 17, 2010

There is no EOF character. EOF by definition "is unequal to any valid character code". Often it is -1. It is not written into the file at any point.

There is a historical EOF character value (CTRL+Z) in DOS, but it is obsolete these days.

To answer the follow-up question of Apoorv: The OS never uses the file data to determine file length (files are not 'null terminated' in any way). So you cannot trick the OS. Perhaps old, stupid programs won't read after CTRL+Z character. I wouldn't assume that any Windows application (even Notepad) would do that. My guess is that it would be easier to trick them with a null (\0) character.