Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   EOF (novice) (http://www.velocityreviews.com/forums/t316280-eof-novice.html)

Alan Connor 11-19-2003 01:02 AM

EOF (novice)
 


--
Alan C this post ends with w
q

From K&R:

#include <stdio.h>

main()

/* copy input to output */

{

int c;

c = getchar();
while (c != EOF) {

putchar(c);
c = getchar();

}

}


If I am reading the text correctly, this program should
terminate when I enter -1 (EOF as defined on my system,
Linux).

But it doesn't. Just keeps right on trucking.

What gives?

AC



Seesaw 11-19-2003 01:30 AM

Re: EOF (novice)
 
When you enter -1, you enter two characters '-' and '1'. Neither equals -1.
Maybe you should enter Ctrl-D(?), which will produce a EOF.

"Alan Connor" <zzzzzz@xxx.yyy> дʼ
news:Fizub.5196$sb4.479@newsread2.news.pas.earthli nk.net...
>
>
> --
> Alan C this post ends with w
> q
>
> From K&R:
>
> #include <stdio.h>
>
> main()
>
> /* copy input to output */
>
> {
>
> int c;
>
> c = getchar();
> while (c != EOF) {
>
> putchar(c);
> c = getchar();
>
> }
>
> }
>
>
> If I am reading the text correctly, this program should
> terminate when I enter -1 (EOF as defined on my system,
> Linux).
>
> But it doesn't. Just keeps right on trucking.
>
> What gives?
>
> AC
>
>




Alex 11-19-2003 01:35 AM

Re: EOF (novice)
 
Alan Connor <zzzzzz@xxx.yyy> wrote:

Absolutely nothing.

Also,

"And sigs are limited to the four lines immediately below the delimiter.

Killfiled for 30 days.

Clean up your act."
Alan Connor, comp.lang.c, Nov 14, 2003.

Alex




Alan Connor 11-19-2003 02:02 AM

Re: EOF (novice)
 
On Wed, 19 Nov 2003 01:30:57 -0000, Seesaw <manseesaw@hotmail.com> wrote:
>
>
> When you enter -1, you enter two characters '-' and '1'. Neither equals -1.
> Maybe you should enter Ctrl-D(?), which will produce a EOF.


Ctrl-c works just fine. But absolutely nothing was said about this
in K&R or the FAQ.

There isn't a single clue to be found.

Yet a large number of people here keep saying that K&R is for
beginners.


AC


Morris Dovey 11-19-2003 03:01 AM

Re: EOF (novice)
 
Alan Connor wrote:
> On Wed, 19 Nov 2003 01:30:57 -0000, Seesaw <manseesaw@hotmail.com> wrote:
>
>>When you enter -1, you enter two characters '-' and '1'. Neither equals -1.
>>Maybe you should enter Ctrl-D(?), which will produce a EOF.

>
> Ctrl-c works just fine. But absolutely nothing was said about this
> in K&R or the FAQ.
>
> There isn't a single clue to be found.
>
> Yet a large number of people here keep saying that K&R is for
> beginners.


Alan...

The mechanism for causing an end-of-file condition to be
recognized varies from platform to platform, from OS to OS, and
sometimes from implementation to implementation. There isn't a
single right answer that could've been included in the FAQ or in K&R.

Usually (but not always), not being able to find some piece of
information in both the FAQ and K&R is a clue that the
information sought will depend on either the platform, OS or
implementation.

But thanks for remembering to check the FAQ before posting.
--
Morris Dovey
West Des Moines, Iowa USA
C links at http://www.iedu.com/c
Read my lips: The apple doesn't fall far from the tree.


Alan Connor 11-19-2003 03:32 AM

Re: EOF (novice)
 
On Tue, 18 Nov 2003 21:01:36 -0600, Morris Dovey <mrdovey@iedu.com> wrote:
>
>
> Alan Connor wrote:
>> On Wed, 19 Nov 2003 01:30:57 -0000, Seesaw <manseesaw@hotmail.com> wrote:
>>
>>>When you enter -1, you enter two characters '-' and '1'. Neither equals -1.
>>>Maybe you should enter Ctrl-D(?), which will produce a EOF.

>>
>> Ctrl-c works just fine. But absolutely nothing was said about this
>> in K&R or the FAQ.
>>
>> There isn't a single clue to be found.
>>
>> Yet a large number of people here keep saying that K&R is for
>> beginners.

>
> Alan...
>
> The mechanism for causing an end-of-file condition to be
> recognized varies from platform to platform, from OS to OS, and
> sometimes from implementation to implementation. There isn't a
> single right answer that could've been included in the FAQ or in K&R.
>
> Usually (but not always), not being able to find some piece of
> information in both the FAQ and K&R is a clue that the
> information sought will depend on either the platform, OS or
> implementation.
>
> But thanks for remembering to check the FAQ before posting.


And the above is EXACTLY what should be in both K&R and the FAQ, as
well as clues such as offered by Seesaw.

Otherwise you have a novice with a program that just won't stop.

and not a clue as to what to do about it.

Thanks much, Morris.

AC


Morris Dovey 11-19-2003 04:39 AM

Re: EOF (novice)
 
Alan Connor wrote:

> On Tue, 18 Nov 2003 21:01:36 -0600, Morris Dovey <mrdovey@iedu.com> wrote:


<snip>

>>Usually (but not always), not being able to find some piece of
>>information in both the FAQ and K&R is a clue that the
>>information sought will depend on either the platform, OS or
>>implementation.


> And the above is EXACTLY what should be in both K&R and the FAQ, as
> well as clues such as offered by Seesaw.
>
> Otherwise you have a novice with a program that just won't stop.
>
> and not a clue as to what to do about it.


Aha! You've just discovered the value of usenet! :-)

A document that answered all possible questions would be
impossibly large - too large to be generally useful. Steve's FAQ
is actually a really good compendium of the /most/ Frequently
Asked Questions (particularly so when we consider that it's free
and the product of donated - but none the less valuable - time
and effort.)

K&R attempts (and succeeds) in providing a /succinct/
presentation of the language. Messrs Kernighan and Ritchie
/don't/ spoon feed the reader; they expect us to read with our
brains fully engaged. It's a different mode of presentation than
used by most authors; and it demands more of the reader. Don't
let yourself be put off just because they're not condescending.

--
Morris Dovey
West Des Moines, Iowa USA
C links at http://www.iedu.com/c
Read my lips: The apple doesn't fall far from the tree.


Alan Connor 11-19-2003 05:32 AM

Re: EOF (novice)
 
On Tue, 18 Nov 2003 22:39:09 -0600, Morris Dovey <mrdovey@iedu.com> wrote:

> K&R attempts (and succeeds) in providing a /succinct/
> presentation of the language. Messrs Kernighan and Ritchie
> /don't/ spoon feed the reader; they expect us to read with our
> brains fully engaged.


That's a strange way to put it: "spoon feed".

It is a book written for people who already know how to
program and want to learn C.

No amount of "brain engaging" could EVER have arrived at
the use of Ctrl-c or Ctrl-d for that program.

There was not a single clue that could possibly lead ANYONE
to those keybindings.

(and I studied the header files too)

Unless they already knew at least a high-level language like
sh (that's me).

And even then, whereas I did USE it, I still couldn't relate
it to the text. I thought it was just an "emergency out."

You seem to attach some sort of stigma to novices, as if
you weren't one yourself at some point.

You were. There was a time when you thought a pointer was
a kind of domestic dog.

--
Alan C this post ends with w
q

Arthur J. O'Dwyer 11-19-2003 05:50 AM

Re: EOF (novice)
 

On Wed, 19 Nov 2003, Alan Connor wrote:
>
> On Tue, 18 Nov 2003 22:39:09 -0600, Morris Dovey <mrdovey@iedu.com> wrote:
> >
> > K&R attempts (and succeeds) in providing a /succinct/
> > presentation of the language. Messrs Kernighan and Ritchie
> > /don't/ spoon feed the reader; they expect us to read with our
> > brains fully engaged.

>
> That's a strange way to put it: "spoon feed".
>
> It is a book written for people who already know how to
> program and want to learn C.
>
> No amount of "brain engaging" could EVER have arrived at
> the use of Ctrl-c or Ctrl-d for that program.


That's because K&R is a book about *C*, not *Unix*. You
wanna learn Unix, go buy a book about Unix. You wanna learn
MS-DOS, go buy a book about MS-DOS. You wanna learn VMS...
well, you get the idea.

> There was not a single clue that could possibly lead ANYONE
> to those keybindings.


Bring it up with Ken Thompson next time you see him.
Personally, I like DOS's Ctrl-Z convention better than
Unix's Ctrl-D, 'cause Z "looks like" EOF in that they're
both ends of things (alphabet and file, respectively).
But that's just not the way your operating system works.

> (and I studied the header files too)
>
> Unless they already knew at least a high-level language like
> sh (that's me).


Good for you. So, knowing sh, and running a Linux
machine, surely you should have used 'cat' once or twice
from the command line, right? If so, you have no excuse.
If not, well, okay, just go back up and read that paragraph
advising you to learn *nix from a *nix book.

> And even then, whereas I did USE it, I still couldn't relate
> it to the text. I thought it was just an "emergency out."


<OT>
Ctrl-C, in Unix, *is* an "emergency out."
Ctrl-D is an EOF "marker" of sorts.
Ctrl-Z will halt the current process.
There are some other Ctrl-[key] combinations that
work on my machine, but they're also off-topic here.
</OT>

HTH,
-Arthur

Mike Wahler 11-19-2003 06:07 AM

Re: EOF (novice)
 
"Alan Connor" <zzzzzz@xxx.yyy> wrote in message
news:KfDub.5447$sb4.4185@newsread2.news.pas.earthl ink.net...
> On Tue, 18 Nov 2003 22:39:09 -0600, Morris Dovey <mrdovey@iedu.com> wrote:
>
> > K&R attempts (and succeeds) in providing a /succinct/
> > presentation of the language. Messrs Kernighan and Ritchie
> > /don't/ spoon feed the reader; they expect us to read with our
> > brains fully engaged.

>
> That's a strange way to put it: "spoon feed".
>
> It is a book written for people who already know how to
> program and want to learn C.
>
> No amount of "brain engaging" could EVER have arrived at
> the use of Ctrl-c or Ctrl-d for that program.


Because neither of those 'keystrokes' (or any others)
are defined by the language. They're defined by the
host operating system.

>
> There was not a single clue that could possibly lead ANYONE
> to those keybindings.


Because C does not have any 'key bindings'. Nor is there
any requirement that standard input be connected to a keyboard
at all.

>
> (and I studied the header files too)
>
> Unless they already knew at least a high-level language like
> sh (that's me).
>
> And even then, whereas I did USE it, I still couldn't relate
> it to the text. I thought it was just an "emergency out."
>
> You seem to attach some sort of stigma to novices, as if
> you weren't one yourself at some point.


I don't think he does. I think Morris does a fine job
of helping novices with C.

>
> You were. There was a time when you thought a pointer was
> a kind of domestic dog.


False context. Shame, shame. :-)

-Mike




All times are GMT. The time now is 04:28 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.