Re: reading line by line from file
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Thu, 30 Mar 2006 00:24:11 GMT
CBFalconer <cbfalconer@xxxxxxxxx> writes:
"Vladimir S. Oka" wrote:
CBFalconer opined:
"Vladimir S. Oka" wrote:
plmanikandan@xxxxxxxxx wrote:
I need to read a file line by line.each line contains different
number of characters.I opened file using fopen function.is there
any function to read the file line by line
Look up `fgets()`.
Among others. Possibly the most convenient is ggets, which is
non-standard, but written in standard C, and available at:
<http://cbfalconer.home.att.net/download/ggets.zip>
Plugging your wares again? ;-)
Good! Anything to get world rid of getses!
Yup. I put it out there in the public domain almost four years
ago, and have had no reports of bugs with it. Some people dislike
the linear buffer increase, but I consider that optimum for the
normal use in interactive input.
I do have one small quibble. Since it quietly strips the newline
character from the input line, there's no good way to tell whether the
last line of an input file had a trailing newline in the first place
(for systems that don't require one).
It's not a huge deal, and it's probably ok as a default behavior, but
it might be nice to have an alternative interface that handles this --
perhaps a second function that leaves the '\n' in place.
<OT>
I like Perl's behavior in this area, but it may not translate well to
C. In Perl, reading a line gives you a string that includes the
trailing newline character; the "chomp" function deletes it. Perl's
strings are variable-length, and are represented in such a way that
"chomp" doesn't have to scan to find the end of the string.
Duplicating this behavior in C might require too much scaffolding,
e.g., returning a structure with additional information rather than
just returning a pointer to a string.
</OT>
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <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.
.
- Follow-Ups:
- Re: reading line by line from file
- From: websnarf
- Re: reading line by line from file
- From: Jordan Abel
- Re: reading line by line from file
- References:
- reading line by line from file
- From: plmanikandan
- Re: reading line by line from file
- From: Vladimir S. Oka
- Re: reading line by line from file
- From: CBFalconer
- Re: reading line by line from file
- From: Vladimir S. Oka
- Re: reading line by line from file
- From: CBFalconer
- reading line by line from file
- Prev by Date: Re: reading line by line from file
- Next by Date: Re: Macro parameter list
- Previous by thread: Re: reading line by line from file
- Next by thread: Re: reading line by line from file
- Index(es):
Relevant Pages
|
|