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

Reading whole text files

P: n/a
I would appreciate opinions on the following:

Given the task to read a _complete_ text file into a string:
What is the "best" way to do it?
Handling the buffer is not the problem -- the character
input is a different matter, at least if I want to remain within
the bounds of the standard library.

Essentially, I can think of three variants:
- Low: Use fgetc(). Simple, straightforward, probably inefficient.
- Default: Use fgets(); ugly, if we are not interested in lines
and have many newline characters to read.
- Interesting: fscanf("%"XSTR(BUFLEN)"c%n", curr, &read), where
XSTR(BUFLEN) gives me BUFLEN in a string literal.

From the labels, it is pretty obvious that I would favour the
last one, so there is the question about possible pitfalls
(yes, I will use the return value and "read") and whether there
are environmental limits for BUFLEN.
If I missed some obvious source (looking for the wrong sort of
stuff in the FAQ and google archives), then please point me
toward it :-)
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 14 '05
Share this Question
Share on Google+
50 Replies

P: n/a
On Wed, 16 Feb 2005 03:14:12 GMT, CBFalconer
<cb********> wrote:
Randy Howard wrote:
Also there is no need for a blank after the '>' _unless_ this is
the initial quoting of the line.

Are we running out of spaces again? Someone please memcpy some
more and share them.

That is simply a move to prevent quotes falling off the right and
getting wrapped by poorer software.

Better to insert more spaces and show up the people who over-quote
(except in a cascade, anything with over 4 levels of quoting is probably
worth deleting).

Chris C
Nov 14 '05 #51

50 Replies

This discussion thread is closed

Replies have been disabled for this discussion.