Re: Question regarding fgets and new lines
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Fri, 24 Nov 2006 02:22:25 -0500
Eric Sosman wrote:
mellyshum123@xxxxxxxx wrote:.... snip ...
I need to read in a comma separated file, and for this I was going
to use fgets. I was reading about it at http://www.cplusplus.com/ref/
and I noticed that the document said:
"Reads characters from stream and stores them in string until
(num -1) characters have been read or a newline or EOF character
is reached, whichever comes first."
If you've used malloc() to obtain memory for the buffer,
another possibility is to use realloc() to make the buffer
larger (preserving the already-read portion) and call fgets()
again to read the tail of the line into the tail of the expanded
buffer. If necessary, you can expand again and again until you
finally get a big enough buffer (or run out of memory). In my
opinion it's a little easier to implement this scheme by using
getc() to read a character at a time instead of using fgets()
to read a batch of characters, but either way it's fairly
straightforward.
Or simply download and use the public domain ggets, at:
<http://cbfalconer.home.att.net/download/>
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
.
- Follow-Ups:
- Re: Question regarding fgets and new lines
- From: Roland Pibinger
- Re: Question regarding fgets and new lines
- References:
- Question regarding fgets and new lines
- From: mellyshum123
- Re: Question regarding fgets and new lines
- From: Eric Sosman
- Question regarding fgets and new lines
- Prev by Date: Re: Question regarding fgets and new lines
- Next by Date: Re: TWISTER 2: Read on....
- Previous by thread: Re: Question regarding fgets and new lines
- Next by thread: Re: Question regarding fgets and new lines
- Index(es):
Relevant Pages
|
|