Re: reading data from a file
- From: Flash Gordon <spam@xxxxxxxxxxxxxxxxxx>
- Date: Wed, 25 Jan 2006 09:28:49 +0000
Jordan Abel wrote:
On 2006-01-24, Flash Gordon <spam@xxxxxxxxxxxxxxxxxx> wrote:Ico wrote:John Smith <JSmith@xxxxxxxx> wrote:To quote from the standard, "A binary stream need notI want to read data from a file and assign it to a dynamically allocated array. I don't know the number of data in advance. My approach has been to read the file twice, the first time to determine its size, the second for the actual assignment. Is there a more efficient way?Open the file with fopen(), seek to the end with fseek(),
meaningfully support fseek calls with a whence value of SEEK_END." So that part of your suggestion is not portable if this is a binary file.
does a text stream need to? you can't seek at all on stdout/stdin on some implementations
<snip>
The call is allowed to fail, as with any library call, and is likely to fail if used on stdio/stdout. However, the quote I gave reads to me that even if a binary stream is seekable you can't rely on being able to seek to its end.
There have been several discussions on here about finding a files size where all this has been mentioned before. I was just pointing out two parts of the standard which explicitly make what was suggested non-portable.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
.
- References:
- reading data from a file
- From: John Smith
- Re: reading data from a file
- From: Ico
- Re: reading data from a file
- From: Flash Gordon
- Re: reading data from a file
- From: Jordan Abel
- reading data from a file
- Prev by Date: Re: database connection to oracle
- Next by Date: Re: database connection to oracle
- Previous by thread: Re: reading data from a file
- Next by thread: Re: reading data from a file
- Index(es):
Relevant Pages
|