Martin Ambuhl <> writes:
> arnuld wrote:
[...]
>> I know fread works butu as authors said, it is designed
>> for reading binary files, whereas I am looking for a function to read
>> text files. Any comments ?
>
> Since every text file is a binary file, you should be able to work
> this out for yourself. fread() and fwrite() are for i/o in which you
> don't want something translating any of what you think the data is
> into something else. If you had read page 363, the beginning of
> chapter 15, you would know that how end-of-line character sequences
> are handled is what divide "text" files from "binary" files. Since
> you can always open so-called text files in binary mode (and all a
> very large class of operating systems there is, in fact, no
> difference), you obviously have no problem to solve.
I don't think your assertion (that every text file is a binary file)
is supported by the standard, nor is your assertion that the handling
of end-of-line sequences is the only difference.
On most of the systems most people use these days (Unix, MS-DOS,
and their derivatives, including Linux, MacOS, and Windows), all
files are sequences of bytes, and text files are differentiated
by end-of-line handling and end-of-file handling (in a DOS/Windows
text file, control-Z is an end-of-file marker). On these systems,
the difference is in how the contents are interpreted.
On some systems, however, the type of a file is part of the
information maintained by the file system. It's entirely possible
to have a conforming C implementation where trying to open a text
file in binary mode, or a binary file in text mode, will always fail.
I, Keith Thompson, <kst->, wrote the above. Permission
to quote anything I've written in this article without the usual
attribution line is granted if and only if this paragraph is quoted
*in full*. If you use an attribution line, feel free to trim.
Martin, I think you could solve all your claimed problems by adding
the word "allegedly" or something similar to your attribution lines.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"