Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Fgets question |
| Date | 2015-07-06 23:13 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <87si91szni.fsf@bsb.me.uk> (permalink) |
| References | <0b5d570e-eed5-4162-b5f9-44b2058639ee@googlegroups.com> |
Paul N <gw7rib@aol.com> writes:
> I just had a moment of doubt about fgets, and rather to my surprise,
> neither MSDN or the C FAQ seemed to answer my question.
>
> If I read a file using fgets, which doesn't end with a newline, am I
> right in thinking that on attempting to read the last line, the
> function will read in the characters that are there, append a nul but
> no newline, and return a non-NULL value?
This is what usually happens, though the standard says that, for a text
stream, the implementation may insist on a terminating new-line
character. ("Whether the last last line requires a terminating new-line
character is implementation-defined.")
> And that next time I try
> fgets, it will return NULL?
Yes.
> So in particular, if fgets(buff, len, fp) returns a non-NULL value,
> then buff[0] is not nul?
Yes.
--
Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Fgets question Paul N <gw7rib@aol.com> - 2015-07-06 14:06 -0700
Re: Fgets question Barry Schwarz <schwarzb@dqel.com> - 2015-07-06 15:09 -0700
Re: Fgets question Keith Thompson <kst-u@mib.org> - 2015-07-06 16:41 -0700
Re: Fgets question Paul N <gw7rib@aol.com> - 2015-07-07 15:16 -0700
Re: Fgets question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-06 23:13 +0100
Re: Fgets question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-07 00:57 +0100
Re: Fgets question Keith Thompson <kst-u@mib.org> - 2015-07-06 16:29 -0700
Re: Fgets question Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-11 05:16 -0700
Re: Fgets question Keith Thompson <kst-u@mib.org> - 2015-07-11 14:04 -0700
Re: Fgets question Richard Damon <Richard@Damon-Family.org> - 2015-07-11 19:56 -0400
Re: Fgets question Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-15 09:26 -0700
Re: Fgets question Keith Thompson <kst-u@mib.org> - 2015-07-15 10:42 -0700
Re: Fgets question Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-20 10:53 -0700
Re: Fgets question Keith Thompson <kst-u@mib.org> - 2015-07-20 12:51 -0700
Re: Fgets question Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-24 10:10 -0700
Re: Fgets question Keith Thompson <kst-u@mib.org> - 2015-07-24 12:15 -0700
Re: Fgets question Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-26 16:41 -0700
Re: Fgets question Keith Thompson <kst-u@mib.org> - 2015-07-27 11:42 -0700
Re: Fgets question Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-30 15:42 -0700
csiph-web