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


Groups > comp.lang.c > #42414

Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead?

From Kaz Kylheku <kaz@kylheku.com>
Newsgroups comp.lang.c
Subject Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead?
Date 2014-03-31 18:55 +0000
Organization Aioe.org NNTP Server
Message-ID <20140331112157.632@kylheku.com> (permalink)
References <c6584a57-8f78-4974-bd65-024577f407ed@googlegroups.com> <getchar-20140331043216@ram.dialup.fu-berlin.de> <5d5b1fa4-586f-4921-85bf-9f698c89c0de@googlegroups.com> <POb_u.127374$sc7.114890@fx33.am4> <lhc9t8$83d$1@speranza.aioe.org>

Show all headers | View raw


On 2014-03-31, glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote:
> BartC <bc@freeuk.com> wrote:
>> <rivkaumiller@gmail.com> wrote in message
>> news:5d5b1fa4-586f-4921-85bf-9f698c89c0de@googlegroups.com...
>  
>>> but the rest of your approach is probably making the thing too
>>> complicated. I dont know why the original author of the "stanza" uses
>>> fscanf() twice, once before the while and once inside the while at the
>>> end.
>  
>> End-of-file checking in C is a bit funny, because you only get an 
>> eof status after attempting to read input.
>
> Seems to me that Pascal is funny, in that it tests EOF before reading
> the end of file. 

In the Pascal wrong, this design is acknowledged as being wrong because it's
not repeated Wirth's successors to Pascal like Oberon and Modula 2.

Modula 2 calls streams "channels".  A read operation produces a result
which is tested afterward. For instance, ReadChar tries to read a character
and store it to a CHAR location via a VAR parameter. Afer ReacChar,
you have to call ReadResult on the channel. Only if that result is allRight
was the character read successfully.

(It's very silly still: ReadChar is a procedure. Why can't it be a function
that returns the read result?)

Oberon calls streams "riders".   The Oberon-2 report doesn't describe
I/O at all, but I found this quote in "Programming in Oberon"
[http://www.ethoberon.ethz.ch/WirthPubl/ProgInOberon.pdf]:

   "The file can thereafter be read by the following pattern. First, the file
   with pecified name is associated with variable f. Then a rider is placed at
   the start o f the file, and then advanced by reading.

     f := Files.Old("MyFile"); Files.Set(r, f, 0);
     WHILE ~r.eof DO Files.Read(f, next); process(next) END

   Note that the rider indicates that the end of the file had been reached
   after the first unsuccessful attempt of reading."

LOL! Note how Wirth points out that EOF is established by a failed read,
but his example tests EOF at the top of the loop, and assumes that
the read succeeded.

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


Thread

How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? rivkaumiller@gmail.com - 2014-03-30 19:04 -0700
  Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? Richard Damon <Richard@Damon-Family.org> - 2014-03-30 22:31 -0400
    Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? rivkaumiller@gmail.com - 2014-03-30 19:43 -0700
      Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? Richard Damon <Richard@Damon-Family.org> - 2014-03-30 23:09 -0400
  Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? rivkaumiller@gmail.com - 2014-03-30 19:35 -0700
  Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? rivkaumiller@gmail.com - 2014-03-30 19:47 -0700
    Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? "BartC" <bc@freeuk.com> - 2014-03-31 11:53 +0100
      Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-03-31 17:50 +0000
        Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? Kaz Kylheku <kaz@kylheku.com> - 2014-03-31 18:55 +0000
          Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? "BartC" <bc@freeuk.com> - 2014-03-31 22:51 +0100
            Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? Kaz Kylheku <kaz@kylheku.com> - 2014-03-31 22:46 +0000
              Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? "BartC" <bc@freeuk.com> - 2014-04-01 00:03 +0100
              Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-03-31 20:33 -0400
                Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? "BartC" <bc@freeuk.com> - 2014-04-01 09:35 +0100
                Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? Keith Thompson <kst-u@mib.org> - 2014-04-01 07:35 -0700
                Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? "BartC" <bc@freeuk.com> - 2014-04-01 17:19 +0100
                Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? Keith Thompson <kst-u@mib.org> - 2014-04-01 10:14 -0700
                Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? "BartC" <bc@freeuk.com> - 2014-04-01 18:59 +0100
                Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? Öö Tiib <ootiib@hot.ee> - 2014-04-04 00:29 -0700
                Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? "BartC" <bc@freeuk.com> - 2014-04-04 12:35 +0100
                Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? Seungbeom Kim <musiphil@bawi.org> - 2014-04-08 11:48 -0700
                Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? Öö Tiib <ootiib@hot.ee> - 2014-04-08 15:52 -0700
                Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-04-02 18:38 +0000
                Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? Keith Thompson <kst-u@mib.org> - 2014-04-02 11:48 -0700
                Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-04-02 23:18 +0000
                Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? Kaz Kylheku <kaz@kylheku.com> - 2014-04-03 00:05 +0000
                Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? James Kuyper <jameskuyper@verizon.net> - 2014-04-02 21:12 -0400
                Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? Keith Thompson <kst-u@mib.org> - 2014-04-02 19:16 -0700
                Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-04-03 03:16 +0000
                Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? James Kuyper <jameskuyper@verizon.net> - 2014-04-02 15:07 -0400
                Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-04-01 23:00 +0100
                Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? Seungbeom Kim <musiphil@bawi.org> - 2014-04-08 11:56 -0700
            Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2014-04-01 02:14 +0300
            Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-04-01 04:52 +0000
              Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? "BartC" <bc@freeuk.com> - 2014-04-01 09:56 +0100
  Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-03-30 22:49 -0400
  Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? James Kuyper <jameskuyper@verizon.net> - 2014-03-30 22:58 -0400
    Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? rivkaumiller@gmail.com - 2014-03-31 09:10 -0700
      Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? James Kuyper <jameskuyper@verizon.net> - 2014-03-31 12:25 -0400
      Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? Keith Thompson <kst-u@mib.org> - 2014-03-31 10:56 -0700
  Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? James Kuyper <jameskuyper@verizon.net> - 2014-03-30 23:09 -0400
  Re: How to modify ((c=getchar())!=NULL) to use fscanf or scanf instead? Keith Thompson <kst-u@mib.org> - 2014-03-31 08:55 -0700

csiph-web