Re: Reading text file contents to a character buffer



On 08/ 3/10 11:16 AM, Ben Bacarisse wrote:
"BGB / cr88192"<cr88192@xxxxxxxxxxx> writes:

personally, I would just be like "to hell with it" and just use fseek/ftell,
since there is almost no way that a text file is going to be larger than 2GB
and expected to just be read into memory like this (it wouldn't fit on 32
bit systems anyways...).

Putting aside the issue of pedantry, it is worth pointing out that ftell
does not report the correct size to read in a whole text file on some
very common platforms. It may usually be a "safe" lie (i.e. you
get told a size larger than required) but it is, none the less, not the
size you need to read.

But on those systems there isn't a direct way of determining the correct size to read without scanning the file. Provided the code doesn't expect the result of a read to exactly match the size requested, all should be well.

--
Ian Collins
.