Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Shortened form of condition |
| Date | 2015-11-10 08:30 -0800 |
| Organization | None to speak of |
| Message-ID | <lnr3jxvmut.fsf@kst-u.example.com> (permalink) |
| References | <b6b2a9ec-4944-4e34-95e1-779161509469@googlegroups.com> <62775b24-22c8-4b78-85ca-6ca99456f2c5@googlegroups.com> <b00e933e-a728-4daa-a36a-0ac6a929991d@googlegroups.com> <3093d138-02fd-4830-82b5-97feec5148e9@googlegroups.com> <87k2pqm7jw.fsf@bsb.me.uk> |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> Alla _ <modelling.data@gmail.com> writes:
> <snip>
>> Exactly. This what I was thinking about, but in that program
>> the author doesn't have EOF condition that turns end_of_text
>> to true, but the condition when the user has not entered any
>> text at all, i.e. text[0] = '\0'. This what confuses me.
>> It would be clear had they offered the EOF condition.
>> Given they didn't, I don't see why the loop should ever
>> terminate.
>
> This is a very interesting remark, though I'm not sure how to help
> dislodge you from this misunderstanding.
I'm not at all sure that this is a misunderstanding, or at least that
it's the one you assume it is.
> You are saying that this is
> clear:
>
> while (end_of_text == 0)
> {
> int ch = fgetc(stdin);
> if (ch == EOF)
> end_of_text = 1;
> else /* do something with the data */
> }
>
> but this
>
> while (end_of_text == 0)
> {
> read_line(text)
> if (text[0] == '\0')
> end_of_text = 1;
> else /* do something with the data */
> }
>
> is not. Mainly, it seems, because the first refers to EOF. Most
> experienced programmer will see these two as slight variation of the
> same pattern.
I'm not sure of that, but it depends on the behavior of the read_line()
function. Based on the code that calls it:
char text[81];
...
read_line (text);
my guess is that read_line() is similar to gets(), except that it
(probably) arbitrarily restricts the input to 80 characters. I don't
see any way to distinguish between an empty line input and an
end-of-file condition. (Perhaps it returns a value that the code
ignores?)
In short, due to apparent limitations in the read_line() function, the
original code terminates on an empty line, not (just) at end-of-file.
It would be useful to see a specification of the read_line() function.
In particular, what does it do (a) at end-of-file, and (b) when reading
an empty line?
--
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
Shortened form of condition Alla _ <modelling.data@gmail.com> - 2015-11-09 06:23 -0800
Re: Shortened form of condition Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-09 14:44 +0000
Re: Shortened form of condition James Kuyper <jameskuyper@verizon.net> - 2015-11-09 10:17 -0500
Re: Shortened form of condition Barry Schwarz <schwarzb@dqel.com> - 2015-11-09 09:20 -0800
Re: Shortened form of condition Alla _ <modelling.data@gmail.com> - 2015-11-09 10:11 -0800
Re: Shortened form of condition Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-09 10:35 -0800
Re: Shortened form of condition Alla _ <modelling.data@gmail.com> - 2015-11-10 00:14 -0800
Re: Shortened form of condition Barry Schwarz <schwarzb@dqel.com> - 2015-11-10 03:04 -0800
Re: Shortened form of condition glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-10 21:42 +0000
Re: Shortened form of condition Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-10 11:13 +0000
Re: Shortened form of condition Alla _ <modelling.data@gmail.com> - 2015-11-10 07:58 -0800
Re: Shortened form of condition Richard Heathfield <rjh@cpax.org.uk> - 2015-11-10 17:06 +0000
Re: Shortened form of condition James Kuyper <jameskuyper@verizon.net> - 2015-11-10 12:11 -0500
Re: Shortened form of condition James Kuyper <jameskuyper@verizon.net> - 2015-11-10 14:01 -0500
Re: Shortened form of condition Keith Thompson <kst-u@mib.org> - 2015-11-10 08:30 -0800
Re: Shortened form of condition Alla _ <modelling.data@gmail.com> - 2015-11-10 09:07 -0800
Re: Shortened form of condition Keith Thompson <kst-u@mib.org> - 2015-11-10 09:29 -0800
Re: Shortened form of condition Alla _ <modelling.data@gmail.com> - 2015-11-10 11:02 -0800
Re: Shortened form of condition Keith Thompson <kst-u@mib.org> - 2015-11-10 11:33 -0800
Re: Shortened form of condition Alla _ <modelling.data@gmail.com> - 2015-11-11 00:28 -0800
Re: Shortened form of condition Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-11 16:05 +0000
Re: Shortened form of condition glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-12 09:29 +0000
Re: Shortened form of condition Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-12 10:56 +0000
Re: Shortened form of condition Richard Heathfield <rjh@cpax.org.uk> - 2015-11-11 16:24 +0000
Re: Shortened form of condition Keith Thompson <kst-u@mib.org> - 2015-11-11 08:53 -0800
Re: Shortened form of condition Richard Heathfield <rjh@cpax.org.uk> - 2015-11-11 16:59 +0000
Re: Shortened form of condition Alla _ <modelling.data@gmail.com> - 2015-11-11 06:42 -0800
Re: Shortened form of condition Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-10 14:04 -0500
Re: Shortened form of condition Barry Schwarz <schwarzb@dqel.com> - 2015-11-10 10:43 -0800
Re: Shortened form of condition James Kuyper <jameskuyper@verizon.net> - 2015-11-09 13:44 -0500
Re: Shortened form of condition Keith Thompson <kst-u@mib.org> - 2015-11-09 10:57 -0800
Re: Shortened form of condition Philip Lantz <prl@canterey.us> - 2015-11-10 01:52 -0800
Re: Shortened form of condition Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-09 19:35 +0000
Re: Shortened form of condition Keith Thompson <kst-u@mib.org> - 2015-11-09 11:52 -0800
Re: Shortened form of condition Alla _ <modelling.data@gmail.com> - 2015-11-10 00:33 -0800
Re: Shortened condition Richard Heathfield <rjh@cpax.org.uk> - 2015-11-10 09:00 +0000
Re: Shortened form of condition Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-10 16:01 -0800
csiph-web