Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #64813

Re: Fgets question

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Fgets question
Date 2015-07-06 16:41 -0700
Organization None to speak of
Message-ID <lnlhesc0r4.fsf@kst-u.example.com> (permalink)
References <0b5d570e-eed5-4162-b5f9-44b2058639ee@googlegroups.com> <qgulpapluk22fv9e33s05pr2gfojj44e96@4ax.com>

Show all headers | View raw


Barry Schwarz <schwarzb@dqel.com> writes:
> On Mon, 6 Jul 2015 14:06:54 -0700 (PDT), Paul N <gw7rib@aol.com>
> wrote:
[...]
>>So in particular, if fgets(buff, len, fp) returns a non-NULL value,
>>then buff[0] is not nul?
>
> That does not  follow.  What you can say is that the value stored in
> buff[0] has been replaced by the first character read from the file.
> Unfortunately, you cannot say what value that character has and it may
> indeed have the value '\0'.  
>
> '\0' is significant in terminating strings.  It has no special
> significance within a file or while performing file input.  How a '\0'
> ended up in the file is a different question but neither fputc nor
> fwrite would have a problem doing so.

Good point, I didn't think about null characters in the file.

On the other hand, an implementation needn't permit null characters in
text files; only printable characters, horizontal tab, and new-line are
guaranteed.

On the other other hand, fgets() can be used on either text or binary
streams.

On the other**3 hand, if you're using fgets() on a binary stream, you're
likely doing something wrong.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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