Edward Rutherford said:
When I call fclose() on a file I've been writing to, does fclose always
write the EOF character before closing the file? Or do I need to write
the EOF myself?
A "EOF character" does not exist. You may expect such a
character to exist since e.g. getc() will return the value
named 'EOF' when the end of the file is reached. But that
doesn't mean that there was a character like that in the
file, this is only a special value returned when the end
of the file has been reached. Incidentally, since getc()
returns the non-character vale EOF under this condition
getc()'s return value is int and not char - since EOF isn't
a char it otherwise would not be possible to return this
value.
Some of the confusion may come from the fact that, if I remember
correctly, in DOS there could be a special character ('^Z') that
in text files was treated by DOS as an end of file marker. But
that character doesn't have anything to do with EOF. If you
want that kind of character in the file then you have to write
it in there tourself, it isn't written into the file by itself.
Another question: If I've got a file opened in update (r+) mode, how can
I delete a character in the file? I want to do this without needing to
create a second file and copy all but the characters I want to delete.
Is there some kind of control sequence that will do this?
There aren't any control sequences to do that. The only way
to do part of the job is by copying all the stuff that comes
after the character you want renoved one place nearer to the
beginning of the file. But then you still need to truncate
the file by one character and, as far as I know, that's only
possible using system specific functions (e.g. under UNIX with
truncate() or ftruncate(), Windows will probably have something
similar). So creating a copy without the character you want to
get rid off, then deleting the old file with remove() and fi-
nally renaming the new file using rename() to give it the
original name is the only way I am aware of when restricting
yourself to using no system-dependent functions and not rely-
ing on implementation-defined behaviour.
Regards, Jens