By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,722 Members | 1,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,722 IT Pros & Developers. It's quick & easy.

file vs. fgets - performance question

P: n/a
I have a large file that I need to put into an array - but I only need the
last hundred or so lines. The file is approx. 1100 lines total (20k). Is
it more efficient to use fgets in a situation like this? I'm wondering if
it's quicker to read into the array only the lines I need (fgets), rather
than converting the whole file into an array (file). Or is file quicker
since I don't need fopen?
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
deko wrote:
I have a large file that I need to put into an array - but I only need the
last hundred or so lines. The file is approx. 1100 lines total (20k). Is
it more efficient to use fgets in a situation like this? I'm wondering if
it's quicker to read into the array only the lines I need (fgets), rather
than converting the whole file into an array (file). Or is file quicker
since I don't need fopen?


the usual file handling routines will be used with file() too. the
difference is that you won't have to take care of it.

maybe you should just try both and benchmark them - i think the
fopen-variant with fgets is faster as it is not reading those many lines.

reg.
s.h.

--
"The goal of Computer Science is to build something that will last at
least until we've finished building it." -- unknown
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.