Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > reading file

Reply
Thread Tools

reading file

 
 
ericunfuk
Guest
Posts: n/a
 
      03-24-2007
I'm wondering if the following is fesible.

I copy a whole file into memory, then I traverse forwards and
backwards in the part of the memory contains the file, to get the
chunk of the file I need?

 
Reply With Quote
 
 
 
 
ericunfuk
Guest
Posts: n/a
 
      03-24-2007
Also, a question about fseek().

Does fseek() clears the EOF if I don't move beyond EOF?

 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      03-24-2007
In article <(E-Mail Removed) om>,
ericunfuk <(E-Mail Removed)> wrote:

>I'm wondering if the following is fesible.
>
>I copy a whole file into memory, then I traverse forwards and
>backwards in the part of the memory contains the file, to get the
>chunk of the file I need?


Perfectly reasonable, if the file is known to be small enough.

For a very large file, where you only need to access small parts of
it, this might be unacceptably inefficient. In such a case you may
find that your operating system provides a way to map files into
memory without reading them unnecessarily, but that's not a standard C
feature. Unix systems provide a function mmap() for this purpose.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      03-24-2007
"ericunfuk" <(E-Mail Removed)> writes:
> Also, a question about fseek().
>
> Does fseek() clears the EOF if I don't move beyond EOF?


What is "the EOF", and what does "beyond EOF" mean?

A more correct statement of your question is:

Does fseek() clear the end-of-file indicator if I don't move beyond
the end of the file?

The answer is yes. C99 7.19.9.2p5 says:

After determining the new position, a successful call to the fseek
function undoes any effects of the ungetc function on the stream,
clears the end-of-file indicator for the stream, and then
establishes the new position.

But why do you care? The end-of-file indicator is set by an attempt
to read past the end of the file. 99% of the time, the correct way to
detect this is to look at the value returned by whatever function you
just used to read from the file; fgetc() returns the value EOF,
fread() returns a number of records smaller than the number you
requested, and so on.

Your system should have documentation that explains all
of this. If you're on a Unix-like system, "man fseek"
should have the answer to your question. For other systems,
the way to read the documentation will vary. And if you're
ambitious, the latest draft of the C standard is available at
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf>; it's
not easy reading, but the index and table of contents are good,
and it has the definitive description of the language and of all the
standard library functions.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
SM Ryan
Guest
Posts: n/a
 
      03-24-2007
Keith Thompson <(E-Mail Removed)> wrote:
# "ericunfuk" <(E-Mail Removed)> writes:
# > Also, a question about fseek().
# >
# > Does fseek() clears the EOF if I don't move beyond EOF?
#
# What is "the EOF", and what does "beyond EOF" mean?

"You never had a single date in high school, did you?"
Buffy Anne Summers

--
SM Ryan http://www.rawbw.com/~wyrmwif/
So....that would make Bethany part black?
 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      03-25-2007
In article <(E-Mail Removed)>,
SM Ryan <(E-Mail Removed)> wrote:

># What is "the EOF", and what does "beyond EOF" mean?


>"You never had a single date in high school, did you?"
> Buffy Anne Summers


I bet you have a database of quotes from every Buffy episode.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading of file by next of map file and by next of file descriptor. =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki C++ 1 07-10-2007 02:46 AM
Reading a file and resuming reading. Karim Ali Python 2 05-25-2007 02:04 PM
UnauthorizedAccessException when reading XML files (no problem when reading other file-types) blabla120@gmx.net ASP .Net 0 09-15-2006 02:08 PM
An Automated process of watching a network file folder, reading a file in it and deleting the file using ASP.NET ? Luis Esteban Valencia Muņoz ASP .Net 3 06-04-2005 10:56 AM
reading the DB vs. reading a text file...performance preference? Darrel ASP .Net 3 11-11-2004 02:27 PM



Advertisments